main
parent
c39f35cbda
commit
933e961d6a
@ -0,0 +1,27 @@
|
||||
# ---> Java
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
|
||||
/target
|
||||
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- 修改cstatm206004,可批量替换 -->
|
||||
<jnlp codebase="http://116.204.84.48:8080/cstatm206004/" href="cstatm206004.jnlp">
|
||||
<information>
|
||||
<title>JWS to Run cstatm</title>
|
||||
<vendor>czldl</vendor>
|
||||
<description>ATM EAGitOps</description>
|
||||
<homepage href="http://116.204.84.48:8080/cstatm206004/index.html"/>
|
||||
<offline-allowed/>
|
||||
</information>
|
||||
<security>
|
||||
<all-permissions/>
|
||||
</security>
|
||||
<update check="always" policy="always"/>
|
||||
<resources>
|
||||
<j2se href="http://java.sun.com/products/autodl/j2se" version="1.6+" />
|
||||
<jar href="app/cstatm206004.jar" main="true"/>
|
||||
</resources>
|
||||
<!-- 修改主类com.atm.view.gui.Gui -->
|
||||
<application-desc name="ATM EAGitOps" main-class="org.atm.view.gui.Gui"/>
|
||||
</jnlp>
|
||||
@ -0,0 +1,117 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<!-- 修改cstatm206004,可批量替换 -->
|
||||
<!-- 1修改groupId:org.atm -->
|
||||
<groupId>org.atm</groupId>
|
||||
<!-- 修改cstatm206004 -->
|
||||
<artifactId>cstatm206004</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<!-- 修改cstatm206004 -->
|
||||
<name>cstatm206004</name>
|
||||
<description>期中考试 cstatm206004</description>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.report.outputEncoding>UTF-8</project.report.outputEncoding>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.release>17</maven.compiler.release>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>42.6.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<version>1.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.1.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.sonarsource.scanner.maven</groupId>
|
||||
<artifactId>sonar-maven-plugin</artifactId>
|
||||
<version>3.10.0.2594</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<!-- 2修改主类com.atm.view.gui.Gui -->
|
||||
<mainClass>
|
||||
org.atm.view.gui.Gui
|
||||
</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.1.2</version>
|
||||
<configuration>
|
||||
<skipTests>false</skipTests>
|
||||
<argLine>${argLine} -Dfile.encoding=UTF-8</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.11</version>
|
||||
<configuration>
|
||||
<skip>false</skip>
|
||||
<destFile>target/coverage-reports/jacoco-unit.exec</destFile>
|
||||
<dataFile>target/coverage-reports/jacoco-unit.exec</dataFile>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>jacoco-initialize</id>
|
||||
<goals>
|
||||
<goal>prepare-agent</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>jacoco-site</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>report</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@ -0,0 +1,15 @@
|
||||
package org.atm.ctrl;
|
||||
|
||||
public class Validate {
|
||||
|
||||
private static final int len = 7;
|
||||
|
||||
public static boolean is7RandNumeric(String str) {
|
||||
boolean flag = str != null && str.matches("\\d{" + len + "}");
|
||||
if (!flag) {
|
||||
System.out.println(str + " must is " + len + " Numeric!");
|
||||
return false;
|
||||
} else
|
||||
return true;
|
||||
}
|
||||
}// end Validate
|
||||
@ -0,0 +1,34 @@
|
||||
package org.atm.dao;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.atm.model.Customer;
|
||||
|
||||
public class Login {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param c
|
||||
*/
|
||||
public Customer login(Customer c) {
|
||||
Customer returnCustomer = null;
|
||||
try {
|
||||
ResultSet rs = DbUtil.executeQuery(
|
||||
"select * from customer where cid='" + c.getCid() + "' and cpin='" + c.getCpin() + "'");
|
||||
if (rs!=null && rs.next()) {
|
||||
returnCustomer = new Customer();
|
||||
returnCustomer.setCid(rs.getString("cid"));
|
||||
returnCustomer.setCpin(rs.getString("cpin"));
|
||||
returnCustomer.setCname(rs.getString("cname"));
|
||||
System.out.println("welcome," + rs.getString("cname"));
|
||||
return returnCustomer;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
System.err.println("Fetch ResultSet Failed!");
|
||||
return returnCustomer;
|
||||
}
|
||||
System.out.println("No Customer!");
|
||||
return returnCustomer;
|
||||
}
|
||||
}// end Login
|
||||
@ -0,0 +1,77 @@
|
||||
package org.atm.model;
|
||||
|
||||
public class Customer {
|
||||
|
||||
private String cid;
|
||||
private String cname;
|
||||
private String cpin;
|
||||
|
||||
public Customer() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cid
|
||||
* @param cpin
|
||||
*/
|
||||
public Customer(String cid, String cpin) {
|
||||
this.cid = cid;
|
||||
this.cpin = cpin;
|
||||
this.cname = "";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cid
|
||||
* @param cpin
|
||||
* @param cname
|
||||
*/
|
||||
public Customer(String cid, String cpin, String cname) {
|
||||
this.cid = cid;
|
||||
this.cpin = cpin;
|
||||
this.cname = cname;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String return the cid
|
||||
*/
|
||||
public String getCid() {
|
||||
return cid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cid the cid to set
|
||||
*/
|
||||
public void setCid(String cid) {
|
||||
this.cid = cid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String return the cname
|
||||
*/
|
||||
public String getCname() {
|
||||
return cname;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cname the cname to set
|
||||
*/
|
||||
public void setCname(String cname) {
|
||||
this.cname = cname;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String return the cpin
|
||||
*/
|
||||
public String getCpin() {
|
||||
return cpin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cpin the cpin to set
|
||||
*/
|
||||
public void setCpin(String cpin) {
|
||||
this.cpin = cpin;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,93 @@
|
||||
package org.atm.view.gui;
|
||||
|
||||
import org.atm.model.Customer;
|
||||
import org.atm.ctrl.Validate;
|
||||
import org.atm.dao.Login;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JPasswordField;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class Gui extends JFrame {
|
||||
|
||||
private JButton jButtonLogin;
|
||||
private JLabel jLabelCid;
|
||||
private JLabel jLabelCpin;
|
||||
private JPanel jPanel;
|
||||
private JPanel jPanelBtn;
|
||||
private JPanel jPanelCid;
|
||||
private JPanel jPanelCpin;
|
||||
private JTextField jTextFieldCid;
|
||||
private JPasswordField jTextFieldCpin;
|
||||
|
||||
public Gui() {
|
||||
this.setTitle("GUI ATM MTE From EA For CS231");
|
||||
this.setSize(300, 200);
|
||||
this.setLocationRelativeTo(null);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setResizable(false);
|
||||
|
||||
jPanel = new JPanel(new GridLayout(3, 1));
|
||||
jPanelCid = new JPanel();
|
||||
jLabelCid = new JLabel("CID");
|
||||
jLabelCid.setForeground(Color.RED);
|
||||
jLabelCid.setFont(new Font("", Font.BOLD, 15));
|
||||
jTextFieldCid = new JTextField(15);
|
||||
jPanelCid.add(jLabelCid);
|
||||
jPanelCid.add(jTextFieldCid);
|
||||
|
||||
jPanelCpin = new JPanel();
|
||||
jLabelCpin = new JLabel("CPIN");
|
||||
jLabelCpin.setForeground(Color.RED);
|
||||
jLabelCpin.setFont(new Font("", Font.BOLD, 15));
|
||||
jTextFieldCpin = new JPasswordField(15);
|
||||
jPanelCpin.add(jLabelCpin);
|
||||
jPanelCpin.add(jTextFieldCpin);
|
||||
|
||||
jPanelBtn = new JPanel();
|
||||
jButtonLogin = new JButton("LOGIN");
|
||||
jPanelBtn.add(jButtonLogin);
|
||||
jPanel.add(jPanelCid);
|
||||
jPanel.add(jPanelCpin);
|
||||
jPanel.add(jPanelBtn);
|
||||
this.add(jPanel);
|
||||
this.setVisible(true);
|
||||
jButtonLogin.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String cid = new String(jTextFieldCid.getText());
|
||||
if (cid.length() <= 0) {
|
||||
JOptionPane.showMessageDialog(null, "CID NULL");
|
||||
System.out.println("CID NULL");
|
||||
} else {
|
||||
String cpin = new String(jTextFieldCpin.getPassword());
|
||||
Customer inputCustomer = new Customer(cid, cpin);
|
||||
Customer returnCustomer = null;
|
||||
if (Validate.is7RandNumeric(cid) && Validate.is7RandNumeric(cpin))
|
||||
returnCustomer = new Login().login(inputCustomer);
|
||||
if (returnCustomer != null) {
|
||||
JOptionPane.showMessageDialog(null, "LOGIN SUCCEEDED!", "PROMPT",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "ID OR PIN ERROR!", "PROMPT",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Gui();
|
||||
}
|
||||
}// end Gui
|
||||
@ -0,0 +1,58 @@
|
||||
package org.atm.ctrl;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import org.atm.ctrl.Validate;
|
||||
|
||||
public class ValidateTest extends junit.framework.TestCase {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param arg0
|
||||
*/
|
||||
public ValidateTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @exception Exception
|
||||
*/
|
||||
protected void setUp()
|
||||
throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @exception Exception
|
||||
*/
|
||||
protected void tearDown()
|
||||
throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public final void testIsNumeric_01_7() {
|
||||
Assert.assertTrue(Validate.is7RandNumeric("2060041"));
|
||||
}
|
||||
public final void testIsNumeric_02_d() {
|
||||
Assert.assertFalse(Validate.is7RandNumeric("123456d"));
|
||||
}
|
||||
public final void testIsNumeric_03_8() {
|
||||
Assert.assertFalse(Validate.is7RandNumeric("12345678"));
|
||||
}
|
||||
public final void testIsNumeric_04_null() {
|
||||
Assert.assertFalse(Validate.is7RandNumeric(""));
|
||||
}
|
||||
public final void testIsNumeric_05_6() {
|
||||
Assert.assertFalse(Validate.is7RandNumeric("123456"));
|
||||
}
|
||||
}// end ValidateTest
|
||||
@ -0,0 +1,16 @@
|
||||
package org.atm.dao;
|
||||
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runner.RunWith;
|
||||
import junit.framework.TestSuite;
|
||||
import junit.framework.Test;
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses({org.atm.ctrl.ValidateTest.class, org.atm.dao.LoginTest.class})
|
||||
public class LoginIntegratedTest {
|
||||
|
||||
public static Test suit() {
|
||||
TestSuite suite = new TestSuite();
|
||||
return suite;
|
||||
}
|
||||
}// end LoginITest
|
||||
@ -0,0 +1,15 @@
|
||||
package org.atm.dao;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import org.atm.dao.Login;
|
||||
import org.atm.model.Customer;
|
||||
|
||||
public class LoginTest extends junit.framework.TestCase {
|
||||
public final void testLogin_01() {
|
||||
Assert.assertNotNull(new Login().login(new Customer("2060041", "2060041")));
|
||||
}
|
||||
public final void testLogin_02() {
|
||||
Assert.assertNull(new Login().login(new Customer("1234578", "1234589")));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue