示例#1
0
 @Test
 public void testPreassignProject() throws Exception {
   s.preassignProject(testProject_1);
   s.preassignProject(s.getRandomPreference());
   assertEquals("there shouldn't be 2 preassigned project", 1, s.getOrderedPreferences().size());
   assertEquals("expect true", true, s.hasPreassignedProject());
 }
示例#2
0
 @Test
 public void testGetOrderedPreferences() throws Exception {
   for (Project str : testProject_rest) {
     s.addProject(str);
   }
   assertEquals("expect equal", testProject_rest, s.getOrderedPreferences());
 }
 @Test
 public void testAddMajor() {
   assertTrue(controller.addStudent("testAddMajor"));
   Iterator i = controller.getStudents().iterator();
   Student s = null;
   while (i.hasNext()) s = (Student) i.next();
   assertNotNull(s);
   assertTrue(controller.setMajor(s, new Major()));
   assertTrue(s.getMajor().getId() == 0);
 }
示例#4
0
  public boolean checkLastName(String lastname) {
    studentList = studentBA.getAllStudents();

    for (Iterator<Student> iterator = studentList.iterator(); iterator.hasNext(); ) {
      Student student = (Student) iterator.next();
      if (student.getLastName().equals(lastname)) {
        return true;
      }
    }
    return false;
  }
示例#5
0
 @Test
 public void testAddProject() {
   int lastIndex = s.getNumberOfPreferences() - 1;
   s.addProject(testProject_1);
   assertEquals(
       "expected addProject to append object at the end of the array.",
       lastIndex + 1,
       s.getProjects().indexOf(testProject_1));
   for (Project project : testProject_rest) {
     s.addProject(project);
   }
   assertEquals(
       "expect to add %d projects.", testProject_rest.size() + 1, s.getNumberOfPreferences());
 }
示例#6
0
 @Test
 public void testGetNumberOfStatedPreferences() {
   assertEquals(0, s.getNumberOfStatedPreferences());
   s.addProject(testProject_1);
   assertEquals(0, s.getNumberOfStatedPreferences());
   for (Project p : testProject_rest) {
     s.addProject(p);
   }
   assertEquals(0, s.getNumberOfStatedPreferences());
   s.setNumberOfStatedPreferences(100);
   assertEquals(100, s.getNumberOfStatedPreferences());
   s.preassignProject(testProject_1);
   assertEquals(1, s.getNumberOfStatedPreferences());
 }
示例#7
0
  public void dropEnrolledSection(Student student, int sectionNo) {
    StudentDao sd = dataAccess.createStudentDao();
    sd.dropEnrolledSection(student, sectionNo);

    SectionDao scd = dataAccess.createSectionDao();
    Section section = scd.getSection(sectionNo);

    student.dropSection(section);
  }
示例#8
0
 @Test
 public void testGetRandomPreference() throws Exception {
   int seed = 123;
   int num = 1;
   List<Project> expected = TheRNG().TestRandomPreferenceUtility(preped_s, seed, num);
   TheRNG().setSeed(seed);
   Project got = preped_s.getRandomPreference();
   assertEquals("should equal", expected.get(0), got);
 }
示例#9
0
 @Before
 public void setUp() throws Exception {
   testProject_1 = new Project("Test The Project of the First Non-Sense");
   s = new Student("test student");
   testProject_rest = new ArrayList<Project>();
   Random r = new Random();
   for (int i = 0; i < 50; i++)
     testProject_rest.add(new Project("test project another " + r.nextInt()));
   preped_s = new Student("I'm prepared");
   for (Project p : testProject_rest) {
     preped_s.addProject(p);
   }
 }
示例#10
0
  public static void main(String[] args) {
    // URL resourceUrl= App.class.getResource("application-config.xml");

    @SuppressWarnings("resource")
    ApplicationContext ctx = new ClassPathXmlApplicationContext("application-config.xml");

    StudentDao studentDao = ctx.getBean("studentDao", StudentDao.class);

    Student student = new Student();
    student.setId(1);

    studentDao.insert(student);

    /*DataSource ds = (DataSource) ctx.getBean("dataSource");
    SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(ds);

    jdbcTemplate.update(sql, args);
    SqlParameterSource parameterSource = new BeanPropertySqlParameterSource(StudentDao);*/

    myBean mb = (myBean) ctx.getBean("myBean");
    System.out.print("hello");
  }
示例#11
0
  private MemberModel() {
    // init memberMap
    memberMap = new HashMap<>();
    // init entitledMap (1 to many relation between memberID and BookNumber)
    entitledMap = new HashMap<>();
    boolean readFlag = false;
    ObjectInputStream oin = null;
    Member tm;
    String[] sa = new String[3];
    try {
      oin = new ObjectInputStream(new FileInputStream("members1.dat"));
      readFlag = true;
    } catch (Exception e) {
      e.printStackTrace();
    }
    // read in from file
    while (readFlag) {
      try {
        // Read a member data from inputstream
        // Structure for reading
        // __________________________________________________________
        // |String|String|String|Boolean or Double|ArrayList<String>|
        // ----------------------------------------------------------

        sa[ID_INDEX] = oin.readUTF();
        sa[TITLE_INDEX] = oin.readUTF();
        sa[PHONENO_INDEX] = oin.readUTF();
        if (sa[ID_INDEX].indexOf("STA") != -1) {
          tm = new Staff(sa[ID_INDEX], sa[TITLE_INDEX], sa[PHONENO_INDEX]);
          ((Staff) tm).setBookOverdue(oin.readBoolean());
        } else {
          tm = new Student(sa[ID_INDEX], sa[TITLE_INDEX], sa[PHONENO_INDEX]);
          ((Student) tm).setFinesOwing(oin.readDouble());
        }
        // Raw data map without relationship to book
        memberMap.put(tm.getMemberID(), tm);
        // Map for storing relation
        entitledMap.put(tm.getMemberID(), (ArrayList<String>) oin.readObject());
      } catch (EOFException e) {
        Log.e(e.getMessage());
        readFlag = false;
      } catch (Exception e) {
        Log.e(e.getMessage());
      }
    }
    try {
      oin.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  /** @return */
  public Student generatStudent() {
    Student student = new Student();
    student.setName(name);
    student.setAddress(address);
    student.setAvaScore(Double.parseDouble(avaScore));
    student.setDiscipline(discipline);
    student.setEmail(email);
    student.setEscClass(Integer.parseInt(escClass));
    student.setFine(fine);
    student.setPoor(poor);

    student.setNote(note);
    student.setSex(sex);
    student.setRalation(ralation);
    student.setRalationTel(ralationTel);
    student.setQq(qq);
    student.setRoom(room);
    /** 把通过查找到的班级属性输入到学生的信息中。这里出错了,先保存一下,下次再处理 */
    StudentClass stClass = mgr.findClassByName(studentClass);
    student.setStudentClass(stClass);
    return student;
  }
 @RequestMapping(value = "/stu/{school}/{stuid}")
 public String find2(Student student) {
   if (student.getSchool().equals("gdut") && student.getStuid().equals("3110006250")) return "yes";
   else return "no";
 }
示例#14
0
 @Test
 public void testGetNumberOfPreferences() throws Exception {
   assertEquals("should equal", testProject_rest.size(), preped_s.getNumberOfPreferences());
 }
示例#15
0
  public String createStudent() throws IOException {

    locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();

    // If locale is English
    if (locale == null || locale == Locale.ENGLISH) {
      locale = Locale.ENGLISH;

      inputStream = this.getClass().getResourceAsStream("/messages.properties");
      if (checkFirstName(firstName) && checkLastName(lastName)) {
        String nameExisted = Props.getProperty(inputStream, "error.existed.name");
        FacesMessage firstNameMessage =
            new FacesMessage(FacesMessage.SEVERITY_ERROR, null, nameExisted);
        FacesMessage lastNameMessage =
            new FacesMessage(FacesMessage.SEVERITY_ERROR, null, nameExisted);
        FacesContext.getCurrentInstance().addMessage("createForm:fNameInput", firstNameMessage);
        FacesContext.getCurrentInstance().addMessage("createForm:lNameInput", lastNameMessage);
        return null;
      } else {
        String createSuccess = Props.getProperty(inputStream, "success.create");
        student = new Student();
        int[] courseIds = new int[studentsCoursesIds.length];
        student = new Student();
        student.setFirstName(firstName);
        student.setLastName(lastName);

        student.setGender(gender);
        student.setAge(age);
        student.setMark(mark);
        for (int i = 0; i < courseIds.length; i++) {
          courseIds[i] = studentsCoursesIds[i];
        }
        student.setCoursesId(courseIds);

        studentBA.createStudent(student, courseIds);

        FacesMessage successful = new FacesMessage(FacesMessage.SEVERITY_INFO, createSuccess, null);
        FacesContext.getCurrentInstance().addMessage(null, successful);

        return "Studentsinfo";
      }

    } else {

      inputStream = this.getClass().getResourceAsStream("/messages_ar.properties");

      if (checkFirstName(firstName) && checkLastName(lastName)) {
        String nameExisted = Props.getProperty(inputStream, "error.existed.name");
        FacesMessage firstNameMessage =
            new FacesMessage(FacesMessage.SEVERITY_ERROR, null, nameExisted);
        FacesMessage lastNameMessage =
            new FacesMessage(FacesMessage.SEVERITY_ERROR, null, nameExisted);
        FacesContext.getCurrentInstance().addMessage("createForm:fNameInput", firstNameMessage);
        FacesContext.getCurrentInstance().addMessage("createForm:lNameInput", lastNameMessage);
        return null;
      } else {
        String createSuccess = Props.getProperty(inputStream, "success.create");
        student = new Student();
        int[] courseIds = new int[studentsCoursesIds.length];
        student = new Student();
        student.setFirstName(firstName);
        student.setLastName(lastName);

        student.setGender(gender);
        student.setAge(age);
        student.setMark(mark);
        for (int i = 0; i < courseIds.length; i++) {
          courseIds[i] = studentsCoursesIds[i];
        }
        student.setCoursesId(courseIds);

        studentBA.createStudent(student, courseIds);

        FacesMessage successful = new FacesMessage(FacesMessage.SEVERITY_INFO, createSuccess, null);
        FacesContext.getCurrentInstance().addMessage(null, successful);

        return "Studentsinfo";
      }
    }
  }
示例#16
0
 @Test
 public void testGetStudentName() throws Exception {
   assertEquals("expect equal", "test student", s.getStudentName());
 }
示例#17
0
 @Test
 public void testHasPreassignedProject() throws Exception {
   s.preassignProject(testProject_1);
   assertEquals("expect equal", true, s.hasPreassignedProject());
 }
示例#18
0
 @Test
 public void testHasReference() throws Exception {
   s.addProject(testProject_1);
   assertEquals("should have this assignment", true, s.hasPreference(testProject_1));
 }
示例#19
0
 @Test
 public void testSetNumberOfStatedPreferences() throws Exception {
   Integer t = 5;
   s.setNumberOfStatedPreferences(t);
   assertEquals("expect 5", 5, s.getNumberOfStatedPreferences());
 }