예제 #1
0
  @After
  public void DeleteData() {
    memberSvc.delete("test1");
    memberSvc.delete("test2");
    memberSvc.delete("test3");

    practiceSvc.delete(DateUtil.toDate("2010-10-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    practiceSvc.delete(DateUtil.toDate("2010-12-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
  }
예제 #2
0
파일: ModelUtil.java 프로젝트: mino8/cnmv
 /**
  * 配列型を文字列に変換する.
  *
  * @param value
  * @return
  */
 @SuppressWarnings("unchecked")
 private static String arrayToString(Object value) {
   // 配列がプリミティブ型の場合はラッパー型配列に変換
   if (value.getClass().getComponentType().isPrimitive()) {
     value = primitiveToWrapperArray(value);
   }
   // ラッパー型配列にキャスト
   Object[] valArray = (Object[]) value;
   StringBuffer sb = new StringBuffer();
   for (Object val : valArray) {
     if (0 < sb.length()) {
       sb.append(",");
     }
     if (val == null) {
       continue;
     } else if (val instanceof Key) {
       //                sb.append(KeyFactory.keyToString((Key)val));
       sb.append(keyToString((Key) val));
     } else if (val instanceof Date) {
       sb.append(DateUtil.toString((Date) val, AppProperties.CNS3_DATE_PATTERN));
     } else if (val instanceof Enum) {
       sb.append(((Enum) val).name());
     } else if (isBaseType(val.getClass())) {
       sb.append(val.toString());
     } else {
       throw new IllegalArgumentException(
           "The class(" + value.getClass().getName() + ") can not be arrayToString.");
     }
   }
   return sb.toString();
 }
예제 #3
0
 @Test
 public void testSearchFromMemberIdAndPracticeDate() throws Exception {
   assertNotNull(
       service.searchFromMemberIdAndPracticeDate(
           "test1", DateUtil.toDate("2010-10-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN)));
   assertNull(
       service.searchFromMemberIdAndPracticeDate(
           "testXXX", DateUtil.toDate("2010-10-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN)));
   assertNull(
       service.searchFromMemberIdAndPracticeDate(
           "test2", DateUtil.toDate("2010-11-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN)));
   assertNull(service.searchFromMemberIdAndPracticeDate("test1", null));
   assertNull(
       service.searchFromMemberIdAndPracticeDate(
           null, DateUtil.toDate("2010-11-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN)));
 }
예제 #4
0
파일: ModelUtil.java 프로젝트: mino8/cnmv
 /**
  * valueを文字列に変換する.
  *
  * @param value
  * @return
  */
 @SuppressWarnings("unchecked")
 public static String valueToString(Object value) {
   String returnStr = null;
   if (value == null) {
     return returnStr;
   } else if (value instanceof String) {
     returnStr = (String) value;
   } else if (Date.class.isAssignableFrom(value.getClass())) {
     returnStr = DateUtil.toString((Date) value, AppProperties.CNS3_DATE_PATTERN);
   } else if (Key.class.isAssignableFrom(value.getClass())) {
     // no-id-yetキーのkeyToString例外対応
     //            returnStr = KeyFactory.keyToString((Key)value);
     returnStr = keyToString((Key) value);
   } else if (Enum.class.isAssignableFrom(value.getClass())) {
     returnStr = ((Enum) value).name();
   } else if (ModelRef.class.isAssignableFrom(value.getClass())) {
     returnStr = keyToString(((ModelRef) value).getKey());
   } else if (isBaseType(value.getClass())) {
     returnStr = ConversionUtil.convert(value, String.class);
   } else if (User.class.isAssignableFrom(value.getClass())) {
     returnStr = UserConverter.getInstance().getAsString(value);
   } else if (GeoPt.class.isAssignableFrom(value.getClass())) {
     returnStr = GeoPtConverter.getInstance().getAsString(value);
   } else if (Text.class.isAssignableFrom(value.getClass())) {
     returnStr = TextConverter.getInstance().getAsString(value);
   } else if (ShortBlob.class.isAssignableFrom(value.getClass())) {
     returnStr = ShortBlobConverter.getInstance().getAsString(value);
   } else if (Blob.class.isAssignableFrom(value.getClass())) {
     returnStr = BlobConverter.getInstance().getAsString(value);
   } else if (Category.class.isAssignableFrom(value.getClass())) {
     returnStr = CategoryConverter.getInstance().getAsString(value);
   } else if (Email.class.isAssignableFrom(value.getClass())) {
     returnStr = EmailConverter.getInstance().getAsString(value);
   } else if (Link.class.isAssignableFrom(value.getClass())) {
     returnStr = LinkConverter.getInstance().getAsString(value);
   } else if (PhoneNumber.class.isAssignableFrom(value.getClass())) {
     returnStr = PhoneNumberConverter.getInstance().getAsString(value);
   } else if (PostalAddress.class.isAssignableFrom(value.getClass())) {
     returnStr = PostalAddressConverter.getInstance().getAsString(value);
   } else if (Rating.class.isAssignableFrom(value.getClass())) {
     returnStr = RatingConverter.getInstance().getAsString(value);
   } else {
     try {
       if (Collection.class.isAssignableFrom(value.getClass())) {
         returnStr = arrayToString(((Collection<?>) value).toArray());
       } else if (value.getClass().isArray()) {
         returnStr = arrayToString(value);
       } else {
         returnStr = SerializableConverter.getInstance().getAsString(value);
       }
     } catch (IllegalArgumentException e) {
       returnStr = SerializableConverter.getInstance().getAsString(value);
     }
   }
   return returnStr;
 }
예제 #5
0
 @Test
 public void testSearchFromPracticeDate() throws Exception {
   assertEquals(
       2,
       service
           .searchFromPracticeDate(
               DateUtil.toDate("2010-10-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN))
           .size());
   assertEquals(
       1,
       service
           .searchFromPracticeDate(
               DateUtil.toDate("2010-12-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN))
           .size());
   assertNull(
       service.searchFromPracticeDate(
           DateUtil.toDate("2010-11-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN)));
   assertNull(service.searchFromPracticeDate(null));
 }
예제 #6
0
 @Test
 public void testSearchFromKey() throws Exception {
   Member m = memberSvc.searchFromId("test1");
   Practice p =
       practiceSvc.searchFromStartDateTime(
           DateUtil.toDate("2010-10-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
   assertNotNull(service.searchFromKey(service.generateKey(m.getKey(), p.getKey())));
   assertNull(service.searchFromKey(Datastore.createKey(Attendance.class, "XXX")));
   assertNull(service.searchFromKey(null));
 }
예제 #7
0
 @Test
 public void testGetInitalizedAttendance() {
   Attendance attendance =
       service.getInitalizedAttendance(
           memberSvc.searchFromId("test3"),
           practiceSvc.searchFromStartDateTime(
               DateUtil.toDate("2010-10-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN)));
   assertEquals(0, attendance.getAttendance());
   assertEquals(memberSvc.searchFromId("test3").getKey(), attendance.getMemberKey());
   assertEquals(
       practiceSvc
           .searchFromStartDateTime(
               DateUtil.toDate("2010-10-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN))
           .getKey(),
       attendance.getPracticeKey());
   assertEquals(false, attendance.getFinished());
   assertEquals(false, attendance.getInputFlg());
   assertNull(attendance.getRacital());
 }
예제 #8
0
  @Test
  public void testRegistListAndDeleteList() throws Exception {
    Attendance a = null;
    Member m = null;
    Practice p = null;
    List<Attendance> attendanceList = new ArrayList<Attendance>();

    a = new Attendance();
    a.setAttendance(1);
    a.setFinished(false);
    a.setRacital("It's racital, too.");
    m = memberSvc.searchFromId("test3");
    a.setMemberKey(m.getKey());
    p =
        practiceSvc.searchFromStartDateTime(
            DateUtil.toDate("2010-10-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    a.setPracticeKey(p.getKey());
    attendanceList.add(a);

    a = new Attendance();
    a.setAttendance(0);
    a.setFinished(true);
    a.setRacital("It's racital, too.");
    m = memberSvc.searchFromId("test3");
    a.setMemberKey(m.getKey());
    p =
        practiceSvc.searchFromStartDateTime(
            DateUtil.toDate("2010-12-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    a.setPracticeKey(p.getKey());
    attendanceList.add(a);

    attendanceList = service.registList(attendanceList);

    assertNotNull(
        service.searchFromMemberIdAndPracticeDate(
            "test3", DateUtil.toDate("2010-10-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN)));
    assertNotNull(
        service.searchFromMemberIdAndPracticeDate(
            "test3", DateUtil.toDate("2010-10-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN)));

    service.deleteList(attendanceList);

    assertNull(
        service.searchFromMemberIdAndPracticeDate(
            "test3", DateUtil.toDate("2010-10-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN)));
    assertNull(
        service.searchFromMemberIdAndPracticeDate(
            "test3", DateUtil.toDate("2010-10-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN)));
  }
예제 #9
0
  @Before
  public void CreateDate() {

    Member m = null;
    Practice p = null;
    Attendance a = null;

    m = new Member();
    m.setId("test1");
    m.setFirstName("taro");
    m.setLastName("test");
    m.setBirthDay(DateUtil.toDate("2010-10-01", DateUtil.ISO_DATE_PATTERN));
    m.setMailAddress("*****@*****.**");
    m.setTelNo("0120-333-906");
    Datastore.put(m);

    m = new Member();
    m.setId("test2");
    m.setFirstName("ziro");
    m.setLastName("test");
    Datastore.put(m);

    m = new Member();
    m.setId("test3");
    m.setFirstName("savuroh");
    m.setLastName("test");
    Datastore.put(m);

    p = new Practice();
    p.setStartDate(DateUtil.toDate("2010-10-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    p.setEndDate(DateUtil.toDate("2010-10-01T12:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    p.setGatheringDate(DateUtil.toDate("2010-10-01T09:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    p.setPracticePlace("test praza");
    p.setGatheringPoint("front of test praza");
    p.setRecital("It's recital.");
    practiceSvc.regist(p);

    p = new Practice();
    p.setStartDate(DateUtil.toDate("2010-10-11T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    p.setEndDate(DateUtil.toDate("2010-10-11T12:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    p.setGatheringDate(DateUtil.toDate("2010-10-11T09:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    practiceSvc.regist(p);

    p = new Practice();
    p.setStartDate(DateUtil.toDate("2010-12-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    p.setEndDate(DateUtil.toDate("2010-12-01T12:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    p.setGatheringDate(DateUtil.toDate("2010-12-01T09:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    practiceSvc.regist(p);

    a = new Attendance();
    a.setAttendance(1);
    a.setFinished(false);
    a.setRacital("It's racital, too.");
    m = memberSvc.searchFromId("test1");
    a.setMemberKey(m.getKey());
    a.getMemberRef().setModel(m);
    p =
        practiceSvc.searchFromStartDateTime(
            DateUtil.toDate("2010-10-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    a.getPracticeRef().setModel(p);
    a.setPracticeKey(p.getKey());
    service.regist(a);

    a = new Attendance();
    a.setAttendance(1);
    a.setFinished(false);
    a.setRacital("It's racital, too.");
    m = memberSvc.searchFromId("test1");
    a.setMemberKey(m.getKey());
    p =
        practiceSvc.searchFromStartDateTime(
            DateUtil.toDate("2010-12-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    a.setPracticeKey(p.getKey());
    service.regist(a);

    a = new Attendance();
    a.setAttendance(0);
    a.setFinished(true);
    a.setRacital("It's racital, too.");
    m = memberSvc.searchFromId("test2");
    a.setMemberKey(m.getKey());
    p =
        practiceSvc.searchFromStartDateTime(
            DateUtil.toDate("2010-10-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    a.setPracticeKey(p.getKey());
    service.regist(a);

    a = new Attendance();
    a.setAttendance(0);
    a.setFinished(true);
    a.setRacital("It's racital, too.");
    m = memberSvc.searchFromId("test2");
    a.setMemberKey(m.getKey());
    p =
        practiceSvc.searchFromStartDateTime(
            DateUtil.toDate("2010-10-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    a.setPracticeKey(p.getKey());
    service.regist(a);

    a = new Attendance();
    a.setAttendance(0);
    a.setFinished(true);
    a.setRacital("It's racital, too.");
    m = memberSvc.searchFromId("test1");
    a.setMemberKey(m.getKey());
    p =
        practiceSvc.searchFromStartDateTime(
            DateUtil.toDate("2010-10-11T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN));
    a.setPracticeKey(p.getKey());
    service.regist(a);
  }
예제 #10
0
 @Test
 public void testSearchFromMemberIdAndPracticeDateSpan() throws Exception {
   assertEquals(
       1,
       service
           .searchFromMemberIdAndPracticeDateSpan(
               "test1",
               DateUtil.toDate("2010-10-10", DateUtil.ISO_DATE_PATTERN),
               DateUtil.toDate("2010-11-30", DateUtil.ISO_DATE_PATTERN))
           .size());
   assertEquals(
       2,
       service
           .searchFromMemberIdAndPracticeDateSpan(
               "test1",
               DateUtil.toDate("2010-10-10", DateUtil.ISO_DATE_PATTERN),
               DateUtil.toDate("2010-12-01", DateUtil.ISO_DATE_PATTERN))
           .size());
   assertEquals(
       2,
       service
           .searchFromMemberIdAndPracticeDateSpan(
               "test1",
               DateUtil.toDate("2010-10-11", DateUtil.ISO_DATE_PATTERN),
               DateUtil.toDate("2010-12-01", DateUtil.ISO_DATE_PATTERN))
           .size());
   assertEquals(
       2,
       service
           .searchFromMemberIdAndPracticeDateSpan(
               "test1",
               DateUtil.toDate("2010-10-11", DateUtil.ISO_DATE_PATTERN),
               DateUtil.toDate("2010-12-02", DateUtil.ISO_DATE_PATTERN))
           .size());
   assertNull(
       service.searchFromMemberIdAndPracticeDateSpan(
           "testXXX",
           DateUtil.toDate("2010-10-01", DateUtil.ISO_DATE_PATTERN),
           DateUtil.toDate("2010-12-01", DateUtil.ISO_DATE_PATTERN)));
   assertEquals(
       1,
       service
           .searchFromMemberIdAndPracticeDateSpan(
               "test2",
               DateUtil.toDate("2010-10-01", DateUtil.ISO_DATE_PATTERN),
               DateUtil.toDate("2010-12-01", DateUtil.ISO_DATE_PATTERN))
           .size());
   assertNull(
       service.searchFromMemberIdAndPracticeDateSpan(
           "test1",
           DateUtil.toDate("2010-10-12", DateUtil.ISO_DATE_PATTERN),
           DateUtil.toDate("2010-11-30", DateUtil.ISO_DATE_PATTERN)));
   assertNull(
       service.searchFromMemberIdAndPracticeDateSpan(
           null,
           DateUtil.toDate("2010-10-02", DateUtil.ISO_DATE_PATTERN),
           DateUtil.toDate("2010-12-02", DateUtil.ISO_DATE_PATTERN)));
   assertNull(
       service.searchFromMemberIdAndPracticeDateSpan(
           "test1", null, DateUtil.toDate("2010-12-02", DateUtil.ISO_DATE_PATTERN)));
   assertNull(
       service.searchFromMemberIdAndPracticeDateSpan(
           "test1", DateUtil.toDate("2010-10-02", DateUtil.ISO_DATE_PATTERN), null));
 }
예제 #11
0
 public void testGetLastDayOfMonth() {
   Date orig = DateUtil.toDate("2003-03-24", "yyyy-MM-dd");
   Date actual = Utils.getLastDayOfMonth(orig);
   assertEquals("2003-03-31", DateUtil.toString(actual));
 }