Project

General

Profile

« Previous | Next » 

Revision 7816

correct regex for whitespace in D1 identifier.

View differences:

test/edu/ucsb/nceas/metacat/dataone/MNodeServiceTest.java
114 114
    suite.addTest(new MNodeServiceTest("initialize"));
115 115
    // MNStorage tests
116 116
    suite.addTest(new MNodeServiceTest("testCreate"));
117
    suite.addTest(new MNodeServiceTest("testCreateInvalidIdentifier"));
117 118
    suite.addTest(new MNodeServiceTest("testUpdate"));
118 119
    // this requires MN certificate
119 120
    suite.addTest(new MNodeServiceTest("testDelete"));
......
1065 1066
    }
1066 1067
    
1067 1068
  }
1069

  
1070
/**
1071
   * Test object creation failure when there is a space in the identifier
1072
   */
1073
  public void testCreateInvalidIdentifier() {
1074
    printTestHeader("testCreateInvalidIdentifier");
1075
    
1076
    try {
1077
      Session session = getTestSession();
1078
      Identifier guid = new Identifier();
1079
      guid.setValue("testCreate withspace." + System.currentTimeMillis());
1080
      InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
1081
      SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
1082
      Identifier pid = MNodeService.getInstance(request).create(session, guid, object, sysmeta);
1083
      fail("Should not be able to create with whitespace in indentifier");
1084
    } catch (InvalidRequest e) {
1085
    	// expect that this request fails
1086
        assertTrue(true);
1087
    } catch (Exception e) {
1088
      e.printStackTrace();
1089
      fail("Unexpected error: " + e.getMessage());
1090
    }
1091
      
1092
  }
1068 1093
  
1069 1094
  
1070 1095
  
src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java
1006 1006
   */
1007 1007
  public static boolean isValidIdentifier(Identifier pid) {
1008 1008
	  if (pid != null && pid.getValue() != null && pid.getValue().length() > 0) {
1009
		  return !pid.getValue().matches("\\s");
1009
		  return !pid.getValue().matches(".*\\s+.*");
1010 1010
	  } 
1011 1011
	  return false;
1012 1012
  }

Also available in: Unified diff