Changeset 1635
- Timestamp:
- 12/01/11 15:04:15 (12 years ago)
- Location:
- ComponentRegistry/branches/jeaferversion/ComponentRegistry/src
- Files:
-
- 1 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/ComponentRegistry.java
r1633 r1635 56 56 int register(AbstractDescription desc, CMDComponentSpec spec); 57 57 58 59 int registerComment(Comment comment, Comment spec); 58 60 /** 59 61 * -
ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/ComponentRegistryImplBase.java
r1633 r1635 20 20 import clarin.cmdi.componentregistry.components.CMDComponentSpec.Header; 21 21 import clarin.cmdi.componentregistry.model.AbstractDescription; 22 import clarin.cmdi.componentregistry.model.Comment; 22 23 import clarin.cmdi.componentregistry.model.ComponentDescription; 23 24 import clarin.cmdi.componentregistry.model.ProfileDescription; … … 106 107 } 107 108 } 108 109 109 110 protected static boolean findComponentId(String componentId, List<CMDComponentType> componentReferences) { 110 111 for (CMDComponentType cmdComponent : componentReferences) { -
ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/CommentsDao.java
r1633 r1635 12 12 import java.sql.Timestamp; 13 13 import java.text.ParseException; 14 import java.util.Collections; 14 15 import java.util.HashMap; 15 16 import java.util.List; … … 97 98 */ 98 99 public String getOwnerPrincipalName(Number id) { 99 StringBuilder select = new StringBuilder("SELECT principal_name FROM " + TABLE_REGISTRY_USER); 100 select.append(" JOIN ").append(getTableName()); 101 select.append(" ON user_id = " + TABLE_REGISTRY_USER + ".id "); 102 select.append(" WHERE ").append(getTableName()).append(".id = ?"); 103 List<String> owner = getSimpleJdbcTemplate().query(select.toString(), new ParameterizedSingleColumnRowMapper<String>(), id); 104 if (owner.isEmpty()) { 105 return null; 106 } else { 107 return owner.get(0); 108 } 109 } 100 StringBuilder select = new StringBuilder("SELECT principal_name FROM " + TABLE_REGISTRY_USER); 101 select.append(" JOIN ").append(getTableName()); 102 select.append(" ON user_id = " + TABLE_REGISTRY_USER + ".id "); 103 select.append(" WHERE ").append(getTableName()).append(".id = ?"); 104 List<String> owner = getSimpleJdbcTemplate().query(select.toString(), new ParameterizedSingleColumnRowMapper<String>(), id); 105 if (owner.isEmpty()) { 106 return null; 107 } else { 108 return owner.get(0); 109 } 110 } 111 110 112 /** 111 113 * … … 114 116 * @throws DataAccessException 115 117 */ 116 public Number insertComment(Comment comment) throws DataAccessException { 117 SimpleJdbcInsert insert = new SimpleJdbcInsert(getDataSource()).withTableName(TABLE_COMMENTS).usingGeneratedKeyColumns( 118 COLUMN_ID); 119 120 Map<String, Object> params = new HashMap<String, Object>(); 118 public Number insertComment(Comment comment, String content, Number userId) throws DataAccessException { 119 TransactionStatus transaction = getTransaction(); 120 try { 121 SimpleJdbcInsert insert = new SimpleJdbcInsert(getDataSource()).withTableName(TABLE_COMMENTS).usingGeneratedKeyColumns( 122 COLUMN_ID); 123 //Number contentId = insert.executeAndReturnKey(Collections.singletonMap("content", (Object) content)); 124 125 SimpleJdbcInsert insertComment = new SimpleJdbcInsert(getDataSource()).withTableName(getTableName()).usingGeneratedKeyColumns(COLUMN_ID); 126 Map<String, Object> params = new HashMap<String, Object>(); 127 putInsertComment(params, comment, content, userId); 128 129 Number id = insertComment.executeAndReturnKey(params); 130 txManager.commit(transaction); 131 return id; 132 } catch (DataAccessException ex) { 133 txManager.rollback(transaction); 134 throw ex; 135 } 136 } 137 138 protected void putInsertComment(Map<String, Object> params, Comment comment, String contentId, Number userId) throws DataAccessException { 139 // SimpleJdbcInsert insert = new SimpleJdbcInsert(getDataSource()).withTableName(TABLE_COMMENTS).usingGeneratedKeyColumns( 140 // COLUMN_ID); 121 141 params.put("comments", comment.getComment()); 122 142 params.put("comment_date", extractTimestamp(comment)); … … 124 144 params.put("profile_description_id", comment.getProfileDescriptionId()); 125 145 params.put("user_id", comment.getUserId()); 126 return insert.executeAndReturnKey(params);127 146 } 128 147 … … 181 200 return getSimpleJdbcTemplate().queryForInt(query.toString(), cmdId); 182 201 } 202 // public Comment getDbId(Number cmId) { 203 // return getFirstOrNull(getSelectStatement("WHERE id=?"), cmId); 204 // } 205 // 206 // private StringBuilder getSelectStatement(String... where) throws DataAccessException { 207 // StringBuilder select = new StringBuilder("SELECT ").append(getCommentColumnList()); 208 // select.append(" FROM ").append(getTableName()); 209 // if (where.length > 0) { 210 // select.append(" "); 211 // for (String str : where) { 212 // select.append(" ").append(str); 213 // } 214 // } 215 // return select; 216 // } 217 // 218 // protected StringBuilder getCommentColumnList() { 219 // 220 // StringBuilder sb = new StringBuilder(); 221 // sb.append(getOrderByColumn()); 222 // sb.append(",comment,comment_date,user_id,"); 223 // return sb; 224 // } 225 // 226 // private String getOrderByColumn() { 227 // return "name"; 228 // } 183 229 184 230 private Timestamp extractTimestamp(Comment comment) { -
ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java
r1633 r1635 230 230 } 231 231 } 232 233 @Override 234 public int registerComment(Comment comment, Comment spec){ 235 try { 236 String xml = commmentSpecToString(spec); 237 // Convert principal name to user record id 238 Number uid = convertUserIdInComment(comment); 239 commentsDao.insertComment(comment, xml, uid); 240 return 0; 241 } catch (DataAccessException ex) { 242 LOG.error("Database error while registering component", ex); 243 return -1; 244 } catch (JAXBException ex) { 245 LOG.error("Error while registering component", ex); 246 return -2; 247 } catch (UnsupportedEncodingException ex) { 248 LOG.error("Error while registering component", ex); 249 return -3; 250 } 251 } 232 252 233 253 /** … … 253 273 if (uid != null) { 254 274 description.setUserId(uid.toString()); 275 } 276 return uid; 277 } 278 279 private Number convertUserIdInComment(Comment comment) throws DataAccessException { 280 Number uid = null; 281 if (comment.getUserId() != null) { 282 User user = userDao.getByPrincipalName(comment.getUserId()); 283 if (user != null) { 284 uid = user.getId(); 285 } 286 } else { 287 uid = userId; 288 } 289 if (uid != null) { 290 comment.setUserId(uid.toString()); 255 291 } 256 292 return uid; … … 460 496 return xml; 461 497 } 498 499 private String commmentSpecToString(Comment spec) throws UnsupportedEncodingException, JAXBException { 500 ByteArrayOutputStream os = new ByteArrayOutputStream(); 501 MDMarshaller.marshal(spec, os); 502 String xml = os.toString("UTF-8"); 503 return xml; 504 } 462 505 463 506 private CMDComponentSpec getUncachedMDComponent(String id, AbstractDescriptionDao dao) { … … 523 566 } 524 567 525 private void checkCommentAge(Comment desc, Principal principal) throws DeleteFailedException {526 if (isPublic() && !configuration.isAdminUser(principal)) {527 try {528 Date regDate = Comment.getDate(desc.getCommentDate());529 Calendar calendar = Calendar.getInstance();530 calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);531 if (regDate.before(calendar.getTime())) { // More then month old532 throw new DeleteFailedException(533 "The "534 + (desc.getId())535 + " is more then a month old and cannot be deleted anymore.");536 }537 } catch (ParseException e) {538 LOG.error("Cannot parse date of " + desc + " Error:" + e);539 }540 }541 }542 543 568 private boolean inWorkspace(AbstractDescriptionDao<?> dao, String cmdId) { 544 569 if (isPublic()) { … … 549 574 } 550 575 551 // private boolean inWorkspace(CommentsDao dao, String cmdId) {552 // if (isPublic()) {553 // return dao.isPublic(cmdId);554 // } else {555 // return dao.isInUserSpace(cmdId, getUserId());556 // }557 // }558 576 @Override 559 577 public String getName() { … … 583 601 try { 584 602 checkAuthorisationComment(com, principal); 585 checkCommentAge(com, principal);586 603 commentsDao.deleteComment(com, true); 587 604 } catch (DataAccessException ex) { -
ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/model/Comment.java
r1633 r1635 103 103 104 104 public static Comment createANewComment() { 105 String id = ComponentRegistry.REGISTRY_ID+ "p_" + IdSequence.get();105 String descriptionId = ComponentRegistry.REGISTRY_ID+ "p_" + IdSequence.get(); 106 106 Comment com = new Comment(); 107 com.setId(id); 107 com.setComment("Actual"); 108 com.setProfileDescriptionId(descriptionId); 108 109 com.setCommentDate(createNewDate()); 109 110 return com; -
ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/model/RegisterResponse.java
r1633 r1635 64 64 this.comment = comment; 65 65 } 66 67 public Comment getComment() { 68 return comment; 69 } 66 70 67 71 public AbstractDescription getDescription() { -
ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java
r1633 r1635 657 657 return registerComment(input, com, userCredentials, userspace, componentId, new NewAction()); 658 658 } 659 660 @POST 661 @Path("/profiles/{profileId}/comments") 662 @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) 663 @Consumes("multipart/form-data") 664 public Response registerCommentInProfile(@FormDataParam(DATA_FORM_FIELD) InputStream input, @FormDataParam(NAME_FORM_FIELD) String comment, 665 @FormDataParam("profileId") AbstractDescription profileId, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) { 666 Principal principal = checkAndGetUserPrincipal(); 667 UserCredentials userCredentials = getUserCredentials(principal); 668 Comment com = createNewComment(); 669 com.setComponentDescriptionId("profileId"); 670 com.setUserId(userCredentials.getPrincipalName()); // Hash used to be created here, now Id is constructed by impl 671 com.setComment(comment); 672 LOG.info("Trying to register Comment: " + com); 673 return registerComment(input, com, userCredentials, userspace, profileId, new NewAction()); 674 } 659 675 660 676 @GET … … 717 733 RegisterResponse response = new RegisterResponse(); 718 734 response.setIsInUserSpace(userspace); 719 validate(response, validator);735 validate(response, commentValidator, validator); 720 736 if (response.getErrors().isEmpty()) { 721 737 Comment spec = validator.getCommentSpec(); -
ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/NewAction.java
r1633 r1635 16 16 @Override 17 17 public int executeComment(Comment com, Comment spec, RegisterResponse response, ComponentRegistry registry) { 18 throw new UnsupportedOperationException("Not supported yet.");18 return registry.registerComment(com, spec); 19 19 } 20 20 -
ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/CommentsDaoTest.java
r1633 r1635 43 43 @Test 44 44 public void testInsertComment() { 45 Comment testComment = createTestComment();45 Comment comment = createTestComment(); 46 46 47 47 48 48 49 String regDate = Comment.createNewDate();50 49 51 50 //testComment.setId(TEST_COMMENT_ID); 52 testComment.setComment("test");53 // testComment.setUserID("1");51 52 //comment.setUserId("1"); 54 53 //testComment.setComponentDescriptionId("A component1"); 55 54 //testComment.setProfileDescriptionId("A profile1"); 56 testComment.setCommentDate(regDate);57 55 56 String testComment = comment.getComment(); 58 57 assertEquals(0, commentsDao.getAllComments().size()); 59 Number newId = commentsDao.insertComment( testComment);58 Number newId = commentsDao.insertComment(comment, testComment, Integer.parseInt(TEST_COMMENT_USER_ID)); 60 59 assertNotNull(newId); 61 60 62 61 List<Comment> comments = commentsDao.getAllComments(); 62 assertNotNull(comments); 63 63 assertEquals(1, comments.size()); 64 64 65 65 assertEquals(TEST_COMMENT_NAME, comments.get(0).getComment()); 66 66 // assertEquals("A component1", comments.get(0).getComponentDescriptionId()); 67 //assertEquals("A profile1", comments.get(0).getProfileDescriptionId());68 assertEquals( regDate, comments.get(0).getCommentDate());69 // assertEquals("1", comments.get(0).getUserId());70 //assertEquals(TEST_COMMENT_ID, comments.get(0).getId());67 assertEquals(TEST_COMMENT_PROFILE_ID, comments.get(0).getProfileDescriptionId()); 68 assertEquals(TEST_COMMENT_DATE, comments.get(0).getCommentDate()); 69 assertEquals(TEST_COMMENT_USER_ID, comments.get(0).getUserId()); 70 //assertEquals(TEST_COMMENT_ID, comments.get(0).getId()); 71 71 } 72 72 … … 90 90 @Test 91 91 public void testGetComment() { 92 Comment testComment = createTestComment(); 93 commentsDao.insertComment(testComment); 92 Comment comment = createTestComment(); 93 String testComment = comment.getComment(); 94 commentsDao.insertComment(comment, testComment, 8); 94 95 95 96 assertNotNull(commentsDao.getByComment(TEST_COMMENT_NAME)); … … 109 110 110 111 public void testSetDelete(){ 111 Comment testComment = createTestComment(); 112 Comment comment = createTestComment(); 113 String testComment = comment.getComment(); 112 114 int count = commentsDao.getAllComments().size(); 113 115 114 commentsDao.insertComment( testComment);116 commentsDao.insertComment(comment, testComment, 8); 115 117 assertEquals(count + 1, commentsDao.getAllComments().size()); 116 118 117 commentsDao.deleteComment( testComment, true);119 commentsDao.deleteComment(comment, true); 118 120 assertEquals(count, commentsDao.getAllComments().size()); 119 121 -
ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java
r1603 r1635 29 29 import clarin.cmdi.componentregistry.impl.database.ComponentRegistryTestDatabase; 30 30 import clarin.cmdi.componentregistry.model.AbstractDescription; 31 import clarin.cmdi.componentregistry.model.Comment; 31 32 import clarin.cmdi.componentregistry.model.ComponentDescription; 32 33 import clarin.cmdi.componentregistry.model.ProfileDescription; … … 38 39 39 40 @RunWith(SpringJUnit4ClassRunner.class) 40 @ContextConfiguration(locations = { "/applicationContext.xml"})41 @ContextConfiguration(locations = {"/applicationContext.xml"}) 41 42 public class ComponentRegistryRestServiceTest extends ComponentRegistryRestServiceTestCase { 42 43 … … 47 48 @Autowired 48 49 private JdbcTemplate jdbcTemplate; 49 50 50 private ComponentRegistry testRegistry; 51 51 52 52 @Before 53 53 public void init() { 54 55 56 57 54 ComponentRegistryTestDatabase.resetAndCreateAllTables(jdbcTemplate); 55 createUserRecord(); 56 // Get public component registry 57 testRegistry = componentRegistryBeanFactory.getNewComponentRegistry(); 58 58 } 59 59 60 60 @Override 61 61 protected String getApplicationContextFile() { 62 62 return "classpath:applicationContext.xml"; 63 63 } 64 64 65 65 private ComponentRegistry getTestRegistry() { 66 66 return testRegistry; 67 67 } 68 68 69 69 private String expectedUserId(String principal) { 70 70 return getUserDao().getByPrincipalName(principal).getId().toString(); 71 71 } 72 72 73 73 private void fillUp() throws Exception { 74 RegistryTestHelper.addProfile(getTestRegistry(), "profile2"); 75 RegistryTestHelper.addProfile(getTestRegistry(), "profile1"); 76 RegistryTestHelper.addComponent(getTestRegistry(), "component2"); 77 RegistryTestHelper.addComponent(getTestRegistry(), "component1"); 78 }; 74 RegistryTestHelper.addProfile(getTestRegistry(), "profile2"); 75 RegistryTestHelper.addProfile(getTestRegistry(), "profile1"); 76 RegistryTestHelper.addComponent(getTestRegistry(), "component2"); 77 RegistryTestHelper.addComponent(getTestRegistry(), "component1"); 78 RegistryTestHelper.addComment(getTestRegistry(), "comment2"); 79 RegistryTestHelper.addComment(getTestRegistry(), "comment1"); 80 81 } 82 83 ; 79 84 80 85 @Test 81 86 public void testGetRegisteredProfiles() throws Exception { 82 83 84 85 86 87 88 89 90 91 87 fillUp(); 88 RegistryTestHelper.addProfile(getTestRegistry(), "PROFILE2"); 89 List<ProfileDescription> response = getResource().path("/registry/profiles").accept(MediaType.APPLICATION_XML).get( 90 PROFILE_LIST_GENERICTYPE); 91 assertEquals(3, response.size()); 92 response = getResource().path("/registry/profiles").accept(MediaType.APPLICATION_JSON).get(PROFILE_LIST_GENERICTYPE); 93 assertEquals(3, response.size()); 94 assertEquals("profile1", response.get(0).getName()); 95 assertEquals("PROFILE2", response.get(1).getName()); 96 assertEquals("profile2", response.get(2).getName()); 92 97 } 93 98 94 99 @Test 95 100 public void testGetRegisteredComponents() throws Exception { 96 97 98 99 100 101 102 103 104 105 101 fillUp(); 102 RegistryTestHelper.addComponent(getTestRegistry(), "COMPONENT2"); 103 List<ComponentDescription> response = getResource().path("/registry/components").accept(MediaType.APPLICATION_XML).get( 104 COMPONENT_LIST_GENERICTYPE); 105 assertEquals(3, response.size()); 106 response = getResource().path("/registry/components").accept(MediaType.APPLICATION_JSON).get(COMPONENT_LIST_GENERICTYPE); 107 assertEquals(3, response.size()); 108 assertEquals("component1", response.get(0).getName()); 109 assertEquals("COMPONENT2", response.get(1).getName()); 110 assertEquals("component2", response.get(2).getName()); 106 111 } 107 112 108 113 @Test 109 114 public void testGetUserComponents() throws Exception { 110 111 112 113 114 115 116 117 118 115 fillUp(); 116 List<ComponentDescription> response = getUserComponents(); 117 assertEquals(0, response.size()); 118 response = getAuthenticatedResource(getResource().path("/registry/components")).accept(MediaType.APPLICATION_JSON).get( 119 COMPONENT_LIST_GENERICTYPE); 120 assertEquals("Get public components", 2, response.size()); 121 ClientResponse cResponse = getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true").accept( 122 MediaType.APPLICATION_JSON).get(ClientResponse.class); 123 assertEquals("Trying to get userspace without credentials", 500, cResponse.getStatus()); 119 124 } 120 125 121 126 @Test 122 127 public void testGetRegisteredComponent() throws Exception { 123 fillUp(); 124 CMDComponentSpec component = getResource().path("/registry/components/clarin.eu:cr1:component1").accept(MediaType.APPLICATION_JSON) 125 .get(CMDComponentSpec.class); 126 assertNotNull(component); 127 assertEquals("Access", component.getCMDComponent().get(0).getName()); 128 component = getResource().path("/registry/components/clarin.eu:cr1:component2").accept(MediaType.APPLICATION_XML).get( 129 CMDComponentSpec.class); 130 assertNotNull(component); 131 assertEquals("Access", component.getCMDComponent().get(0).getName()); 132 133 assertEquals("clarin.eu:cr1:component2", component.getHeader().getID()); 134 assertEquals("component2", component.getHeader().getName()); 135 assertEquals("Test Description", component.getHeader().getDescription()); 128 fillUp(); 129 CMDComponentSpec component = getResource().path("/registry/components/clarin.eu:cr1:component1").accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class); 130 assertNotNull(component); 131 assertEquals("Access", component.getCMDComponent().get(0).getName()); 132 component = getResource().path("/registry/components/clarin.eu:cr1:component2").accept(MediaType.APPLICATION_XML).get( 133 CMDComponentSpec.class); 134 assertNotNull(component); 135 assertEquals("Access", component.getCMDComponent().get(0).getName()); 136 137 assertEquals("clarin.eu:cr1:component2", component.getHeader().getID()); 138 assertEquals("component2", component.getHeader().getName()); 139 assertEquals("Test Description", component.getHeader().getDescription()); 140 } 141 142 @Test 143 public void testGetRegisteredCommentsInProfile() throws Exception { 144 fillUp(); 145 RegistryTestHelper.addComment(getTestRegistry(), "COMMENT1"); 146 List<Comment> response = getResource().path("/registry/profiles/clarin.eu:cr1:profile1/comments").accept(MediaType.APPLICATION_XML). 147 get(COMMENT_LIST_GENERICTYPE); 148 assertEquals(0, response.size()); 149 response = getResource().path("/registry/components/clarin.eu:cr1:profile1/comments").accept(MediaType.APPLICATION_JSON).get( 150 COMMENT_LIST_GENERICTYPE); 151 assertEquals(3, response.size()); 152 assertEquals("comment1", response.get(0).getComment()); 153 assertEquals("comment2", response.get(1).getComment()); 154 assertEquals("COMMENT1", response.get(2).getComment()); 136 155 } 137 156 138 157 @Test 139 158 public void testDeleteRegisteredComponent() throws Exception { 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 fillUp(); 160 List<ComponentDescription> components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE); 161 assertEquals(2, components.size()); 162 CMDComponentSpec profile = getResource().path("/registry/components/clarin.eu:cr1:component1").get(CMDComponentSpec.class); 163 assertNotNull(profile); 164 ClientResponse response = getAuthenticatedResource("/registry/components/clarin.eu:cr1:component1").delete(ClientResponse.class); 165 assertEquals(200, response.getStatus()); 166 167 components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE); 168 assertEquals(1, components.size()); 169 170 response = getAuthenticatedResource("/registry/components/clarin.eu:cr1:component2").delete(ClientResponse.class); 171 assertEquals(200, response.getStatus()); 172 173 components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE); 174 assertEquals(0, components.size()); 175 176 response = getAuthenticatedResource("/registry/components/clarin.eu:cr1:component1").delete(ClientResponse.class); 177 assertEquals(200, response.getStatus()); 159 178 } 160 179 161 180 @Test 162 181 public void testDeleteRegisteredComponentStillUsed() throws Exception { 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 182 String content = ""; 183 content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; 184 content += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; 185 content += " <Header/>\n"; 186 content += " <CMD_Component name=\"XXX\" CardinalityMin=\"1\" CardinalityMax=\"10\">\n"; 187 content += " <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n"; 188 content += " </CMD_Component>\n"; 189 content += "</CMD_ComponentSpec>\n"; 190 ComponentDescription compDesc1 = RegistryTestHelper.addComponent(getTestRegistry(), "XXX1", content); 191 192 content = ""; 193 content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; 194 content += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; 195 content += " <Header/>\n"; 196 content += " <CMD_Component name=\"YYY\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n"; 197 content += " <CMD_Component ComponentId=\"" + compDesc1.getId() + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n"; 198 content += " </CMD_Component>\n"; 199 content += " </CMD_Component>\n"; 200 content += "</CMD_ComponentSpec>\n"; 201 ComponentDescription compDesc2 = RegistryTestHelper.addComponent(getTestRegistry(), "YYY1", content); 202 203 content = ""; 204 content += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; 205 content += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; 206 content += " <Header/>\n"; 207 content += " <CMD_Component name=\"ZZZ\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n"; 208 content += " <CMD_Component ComponentId=\"" + compDesc1.getId() + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n"; 209 content += " </CMD_Component>\n"; 210 content += " </CMD_Component>\n"; 211 content += "</CMD_ComponentSpec>\n"; 212 ProfileDescription profile = RegistryTestHelper.addProfile(getTestRegistry(), "TestProfile3", content); 213 214 List<ComponentDescription> components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE); 215 assertEquals(2, components.size()); 216 217 ClientResponse response = getAuthenticatedResource("/registry/components/" + compDesc1.getId()).delete(ClientResponse.class); 218 assertEquals(Status.FORBIDDEN.getStatusCode(), response.getStatus()); 219 assertEquals( 220 "Still used by the following profiles: \n - TestProfile3\nStill used by the following components: \n - YYY1\nTry to change above mentioned references first.", 221 response.getEntity(String.class)); 222 223 components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE); 224 assertEquals(2, components.size()); 225 226 response = getAuthenticatedResource("/registry/profiles/" + profile.getId()).delete(ClientResponse.class); 227 assertEquals(200, response.getStatus()); 228 response = getAuthenticatedResource("/registry/components/" + compDesc2.getId()).delete(ClientResponse.class); 229 assertEquals(200, response.getStatus()); 230 response = getAuthenticatedResource("/registry/components/" + compDesc1.getId()).delete(ClientResponse.class); 231 assertEquals(200, response.getStatus()); 232 components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE); 233 assertEquals(0, components.size()); 215 234 } 216 235 217 236 @Test 218 237 public void testGetRegisteredProfile() throws Exception { 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 238 fillUp(); 239 CMDComponentSpec profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile1").accept(MediaType.APPLICATION_JSON).get( 240 CMDComponentSpec.class); 241 assertNotNull(profile); 242 assertEquals("Actor", profile.getCMDComponent().get(0).getName()); 243 profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile2").accept(MediaType.APPLICATION_XML).get( 244 CMDComponentSpec.class); 245 assertNotNull(profile); 246 assertEquals("Actor", profile.getCMDComponent().get(0).getName()); 247 248 assertEquals("clarin.eu:cr1:profile2", profile.getHeader().getID()); 249 assertEquals("profile2", profile.getHeader().getName()); 250 assertEquals("Test Description", profile.getHeader().getDescription()); 251 252 try { 253 profile = getResource().path("/registry/profiles/clarin.eu:cr1:profileXXXX").accept(MediaType.APPLICATION_XML).get( 254 CMDComponentSpec.class); 255 fail("Exception should have been thrown resource does not exist, HttpStatusCode 204"); 256 } catch (UniformInterfaceException e) { 257 assertEquals(204, e.getResponse().getStatus()); 258 } 240 259 } 241 260 242 261 @Test 243 262 public void testGetRegisteredProfileRawData() throws Exception { 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 263 fillUp(); 264 String profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile1/xsd").accept(MediaType.TEXT_XML).get(String.class); 265 assertTrue(profile.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema")); 266 assertTrue(profile.endsWith("</xs:schema>")); 267 268 profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile1/xml").accept(MediaType.TEXT_XML).get(String.class); 269 assertTrue(profile.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<CMD_ComponentSpec")); 270 assertTrue(profile.endsWith("</CMD_ComponentSpec>\n")); 271 assertTrue(profile.contains("xsi:schemaLocation")); 272 273 try { 274 getResource().path("/registry/components/clarin.eu:cr1:component1/xsl").accept(MediaType.TEXT_XML).get(String.class); 275 fail("Should have thrown exception, unsupported path parameter"); 276 } catch (UniformInterfaceException e) {//server error 277 } 259 278 } 260 279 261 280 @Test 262 281 public void testPrivateProfileXsd() throws Exception { 263 FormDataMultiPart form = createFormData(RegistryTestHelper.getTestProfileContent()); 264 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")) 265 .type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form); 266 assertTrue(response.isProfile()); 267 assertEquals(1, getUserProfiles().size()); 268 AbstractDescription desc = response.getDescription(); 269 String profile = getResource().path("/registry/profiles/" + desc.getId() + "/xsd").accept(MediaType.TEXT_XML).get(String.class); 270 assertTrue(profile.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema")); 271 assertTrue(profile.endsWith("</xs:schema>")); 282 FormDataMultiPart form = createFormData(RegistryTestHelper.getTestProfileContent()); 283 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")).type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form); 284 assertTrue(response.isProfile()); 285 assertEquals(1, getUserProfiles().size()); 286 AbstractDescription desc = response.getDescription(); 287 String profile = getResource().path("/registry/profiles/" + desc.getId() + "/xsd").accept(MediaType.TEXT_XML).get(String.class); 288 assertTrue(profile.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema")); 289 assertTrue(profile.endsWith("</xs:schema>")); 272 290 } 273 291 274 292 @Test 275 293 public void testPrivateComponentXsd() throws Exception { 276 FormDataMultiPart form = createFormData(RegistryTestHelper.getComponentTestContent()); 277 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")) 278 .type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form); 279 assertFalse(response.isProfile()); 280 assertEquals(1, getUserComponents().size()); 281 AbstractDescription desc = response.getDescription(); 282 String profile = getResource().path("/registry/components/" + desc.getId() + "/xsd").accept(MediaType.TEXT_XML).get(String.class); 283 assertTrue(profile.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema")); 284 assertTrue(profile.endsWith("</xs:schema>")); 294 FormDataMultiPart form = createFormData(RegistryTestHelper.getComponentTestContent()); 295 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")).type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form); 296 assertFalse(response.isProfile()); 297 assertEquals(1, getUserComponents().size()); 298 AbstractDescription desc = response.getDescription(); 299 String profile = getResource().path("/registry/components/" + desc.getId() + "/xsd").accept(MediaType.TEXT_XML).get(String.class); 300 assertTrue(profile.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema")); 301 assertTrue(profile.endsWith("</xs:schema>")); 285 302 } 286 303 287 304 @Test 288 305 public void testDeleteRegisteredProfile() throws Exception { 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 306 fillUp(); 307 List<ProfileDescription> profiles = getResource().path("/registry/profiles").get(PROFILE_LIST_GENERICTYPE); 308 assertEquals(2, profiles.size()); 309 CMDComponentSpec profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile1").get(CMDComponentSpec.class); 310 assertNotNull(profile); 311 312 ClientResponse response = getAuthenticatedResource("/registry/profiles/clarin.eu:cr1:profile1").delete(ClientResponse.class); 313 assertEquals(200, response.getStatus()); 314 315 profiles = getResource().path("/registry/profiles").get(PROFILE_LIST_GENERICTYPE); 316 assertEquals(1, profiles.size()); 317 318 response = getAuthenticatedResource("/registry/profiles/clarin.eu:cr1:profile2").delete(ClientResponse.class); 319 assertEquals(200, response.getStatus()); 320 321 profiles = getResource().path("/registry/profiles").get(PROFILE_LIST_GENERICTYPE); 322 assertEquals(0, profiles.size()); 323 324 response = getAuthenticatedResource("/registry/profiles/clarin.eu:cr1:profile1").delete(ClientResponse.class); 325 assertEquals(200, response.getStatus()); 309 326 } 310 327 311 328 @Test 312 329 public void testGetRegisteredComponentRawData() throws Exception { 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 330 fillUp(); 331 String component = getResource().path("/registry/components/clarin.eu:cr1:component1/xsd").accept(MediaType.TEXT_XML).get( 332 String.class); 333 assertTrue(component.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema")); 334 assertTrue(component.endsWith("</xs:schema>")); 335 336 component = getResource().path("/registry/components/clarin.eu:cr1:component1/xml").accept(MediaType.TEXT_XML).get(String.class); 337 assertTrue(component.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<CMD_ComponentSpec")); 338 assertTrue(component.endsWith("</CMD_ComponentSpec>\n")); 339 assertTrue(component.contains("xsi:schemaLocation")); 340 341 try { 342 getResource().path("/registry/components/clarin.eu:cr1:component1/jpg").accept(MediaType.TEXT_XML).get(String.class); 343 fail("Should have thrown exception, unsopported path parameter"); 344 } catch (UniformInterfaceException e) { 345 } 329 346 } 330 347 331 348 @Test 332 349 public void testRegisterProfile() throws Exception { 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 350 FormDataMultiPart form = new FormDataMultiPart(); 351 form.field(ComponentRegistryRestService.DATA_FORM_FIELD, RegistryTestHelper.getTestProfileContent(), 352 MediaType.APPLICATION_OCTET_STREAM_TYPE); 353 form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "ProfileTest1"); 354 form.field(ComponentRegistryRestService.DOMAIN_FORM_FIELD, "TestDomain"); 355 form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, "My Test Profile"); 356 form.field(ComponentRegistryRestService.GROUP_FORM_FIELD, "My Test Group"); 357 RegisterResponse response = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post( 358 RegisterResponse.class, form); 359 assertTrue(response.isProfile()); 360 assertFalse(response.isInUserSpace()); 361 ProfileDescription profileDesc = (ProfileDescription) response.getDescription(); 362 assertNotNull(profileDesc); 363 assertEquals("ProfileTest1", profileDesc.getName()); 364 assertEquals("My Test Profile", profileDesc.getDescription()); 365 assertEquals("TestDomain", profileDesc.getDomainName()); 366 assertEquals("My Test Group", profileDesc.getGroupName()); 367 assertEquals(expectedUserId("JUnit@test.com"), profileDesc.getUserId()); 368 assertEquals("JUnit@test.com", profileDesc.getCreatorName()); 369 assertTrue(profileDesc.getId().startsWith(ComponentRegistry.REGISTRY_ID + "p_")); 370 assertNotNull(profileDesc.getRegistrationDate()); 371 assertEquals("http://localhost:9998/registry/profiles/" + profileDesc.getId(), profileDesc.getHref()); 355 372 } 356 373 357 374 @Test 358 375 public void testPublishProfile() throws Exception { 359 assertEquals("user registered profiles", 0, getUserProfiles().size()); 360 assertEquals("public registered profiles", 0, getPublicProfiles().size()); 361 FormDataMultiPart form = createFormData(RegistryTestHelper.getTestProfileContent(), "Unpublished"); 362 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")) 363 .type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form); 364 assertTrue(response.isProfile()); 365 AbstractDescription desc = response.getDescription(); 366 assertEquals("Unpublished", desc.getDescription()); 367 assertEquals(1, getUserProfiles().size()); 368 assertEquals(0, getPublicProfiles().size()); 369 form = createFormData(RegistryTestHelper.getTestProfileContent("publishedName"), "Published"); 370 response = getAuthenticatedResource(getResource().path("/registry/profiles/" + desc.getId() + "/publish")).type( 371 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form); 372 373 assertEquals(0, getUserProfiles().size()); 374 List<ProfileDescription> profiles = getPublicProfiles(); 375 assertEquals(1, profiles.size()); 376 ProfileDescription profileDescription = profiles.get(0); 377 assertNotNull(profileDescription.getId()); 378 assertEquals(desc.getId(), profileDescription.getId()); 379 assertEquals("http://localhost:9998/registry/profiles/" + desc.getId(), profileDescription.getHref()); 380 assertEquals("Published", profileDescription.getDescription()); 381 CMDComponentSpec spec = getPublicSpec(profileDescription); 382 assertEquals("publishedName", spec.getCMDComponent().get(0).getName()); 376 assertEquals("user registered profiles", 0, getUserProfiles().size()); 377 assertEquals("public registered profiles", 0, getPublicProfiles().size()); 378 FormDataMultiPart form = createFormData(RegistryTestHelper.getTestProfileContent(), "Unpublished"); 379 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")).type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form); 380 assertTrue(response.isProfile()); 381 AbstractDescription desc = response.getDescription(); 382 assertEquals("Unpublished", desc.getDescription()); 383 assertEquals(1, getUserProfiles().size()); 384 assertEquals(0, getPublicProfiles().size()); 385 form = createFormData(RegistryTestHelper.getTestProfileContent("publishedName"), "Published"); 386 response = getAuthenticatedResource(getResource().path("/registry/profiles/" + desc.getId() + "/publish")).type( 387 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form); 388 389 assertEquals(0, getUserProfiles().size()); 390 List<ProfileDescription> profiles = getPublicProfiles(); 391 assertEquals(1, profiles.size()); 392 ProfileDescription profileDescription = profiles.get(0); 393 assertNotNull(profileDescription.getId()); 394 assertEquals(desc.getId(), profileDescription.getId()); 395 assertEquals("http://localhost:9998/registry/profiles/" + desc.getId(), profileDescription.getHref()); 396 assertEquals("Published", profileDescription.getDescription()); 397 CMDComponentSpec spec = getPublicSpec(profileDescription); 398 assertEquals("publishedName", spec.getCMDComponent().get(0).getName()); 383 399 } 384 400 385 401 private CMDComponentSpec getPublicSpec(AbstractDescription desc) { 386 387 388 389 390 402 if (desc.isProfile()) { 403 return getResource().path("/registry/profiles/" + desc.getId()).get(CMDComponentSpec.class); 404 } else { 405 return getResource().path("/registry/components/" + desc.getId()).get(CMDComponentSpec.class); 406 } 391 407 } 392 408 393 409 @Test 394 410 public void testPublishComponent() throws Exception { 395 assertEquals(0, getUserComponents().size()); 396 assertEquals(0, getPublicComponents().size()); 397 FormDataMultiPart form = createFormData(RegistryTestHelper.getComponentTestContent(), "Unpublished"); 398 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")) 399 .type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form); 400 assertFalse(response.isProfile()); 401 AbstractDescription desc = response.getDescription(); 402 assertEquals("Unpublished", desc.getDescription()); 403 assertEquals(1, getUserComponents().size()); 404 assertEquals(0, getPublicComponents().size()); 405 form = createFormData(RegistryTestHelper.getComponentTestContent("publishedName"), "Published"); 406 response = getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId() + "/publish")).type( 407 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form); 408 409 assertEquals(0, getUserComponents().size()); 410 List<ComponentDescription> components = getPublicComponents(); 411 assertEquals(1, components.size()); 412 ComponentDescription componentDescription = components.get(0); 413 assertNotNull(componentDescription.getId()); 414 assertEquals(desc.getId(), componentDescription.getId()); 415 assertEquals("http://localhost:9998/registry/components/" + desc.getId(), componentDescription.getHref()); 416 assertEquals("Published", componentDescription.getDescription()); 417 CMDComponentSpec spec = getPublicSpec(componentDescription); 418 assertEquals("publishedName", spec.getCMDComponent().get(0).getName()); 411 assertEquals(0, getUserComponents().size()); 412 assertEquals(0, getPublicComponents().size()); 413 FormDataMultiPart form = createFormData(RegistryTestHelper.getComponentTestContent(), "Unpublished"); 414 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")).type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form); 415 assertFalse(response.isProfile()); 416 AbstractDescription desc = response.getDescription(); 417 assertEquals("Unpublished", desc.getDescription()); 418 assertEquals(1, getUserComponents().size()); 419 assertEquals(0, getPublicComponents().size()); 420 form = createFormData(RegistryTestHelper.getComponentTestContent("publishedName"), "Published"); 421 response = getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId() + "/publish")).type( 422 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form); 423 424 assertEquals(0, getUserComponents().size()); 425 List<ComponentDescription> components = getPublicComponents(); 426 assertEquals(1, components.size()); 427 ComponentDescription componentDescription = components.get(0); 428 assertNotNull(componentDescription.getId()); 429 assertEquals(desc.getId(), componentDescription.getId()); 430 assertEquals("http://localhost:9998/registry/components/" + desc.getId(), componentDescription.getHref()); 431 assertEquals("Published", componentDescription.getDescription()); 432 CMDComponentSpec spec = getPublicSpec(componentDescription); 433 assertEquals("publishedName", spec.getCMDComponent().get(0).getName()); 419 434 } 420 435 421 436 @Test 422 437 public void testRegisterUserspaceProfile() throws Exception { 423 List<ProfileDescription> profiles = getUserProfiles(); 424 assertEquals("user registered profiles", 0, profiles.size()); 425 assertEquals("public registered profiles", 0, getPublicProfiles().size()); 426 FormDataMultiPart form = createFormData(RegistryTestHelper.getTestProfileContent()); 427 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")) 428 .type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form); 429 assertTrue(response.isProfile()); 430 assertTrue(response.isInUserSpace()); 431 ProfileDescription profileDesc = (ProfileDescription) response.getDescription(); 432 assertNotNull(profileDesc); 433 assertEquals("Test1", profileDesc.getName()); 434 assertEquals("My Test", profileDesc.getDescription()); 435 assertEquals(expectedUserId("JUnit@test.com"), profileDesc.getUserId()); 436 assertEquals("JUnit@test.com", profileDesc.getCreatorName()); 437 assertTrue(profileDesc.getId().startsWith(ComponentRegistry.REGISTRY_ID + "p_")); 438 assertNotNull(profileDesc.getRegistrationDate()); 439 assertEquals("http://localhost:9998/registry/profiles/" + profileDesc.getId() + "?userspace=true", profileDesc.getHref()); 440 441 profiles = getUserProfiles(); 442 assertEquals(1, profiles.size()); 443 assertEquals(0, getPublicProfiles().size()); 444 // Try get from public registry 445 ClientResponse cResponse = getResource().path("/registry/profiles/" + profileDesc.getId()).accept(MediaType.APPLICATION_XML).get( 446 ClientResponse.class); 447 // Should return 204 = no content 448 assertEquals(204, cResponse.getStatus()); 449 CMDComponentSpec spec = getAuthenticatedResource( 450 getResource().path("/registry/profiles/" + profileDesc.getId()).queryParam(USERSPACE_PARAM, "true")).accept( 451 MediaType.APPLICATION_XML).get(CMDComponentSpec.class); 452 assertNotNull(spec); 453 454 cResponse = getResource().path("/registry/profiles/" + profileDesc.getId() + "/xsd").accept(MediaType.TEXT_XML).get( 455 ClientResponse.class); 456 assertEquals(200, cResponse.getStatus()); 457 String profile = cResponse.getEntity(String.class); 458 assertTrue(profile.length() > 0); 459 460 profile = getAuthenticatedResource(getResource().path("/registry/profiles/" + profileDesc.getId() + "/xml")).accept( 461 MediaType.TEXT_XML).get(String.class); 462 assertTrue(profile.length() > 0); 463 464 cResponse = getAuthenticatedResource( 465 getResource().path("/registry/profiles/" + profileDesc.getId()).queryParam(USERSPACE_PARAM, "true")).delete( 466 ClientResponse.class); 467 assertEquals(200, cResponse.getStatus()); 468 469 profiles = getUserProfiles(); 470 assertEquals(0, profiles.size()); 438 List<ProfileDescription> profiles = getUserProfiles(); 439 assertEquals("user registered profiles", 0, profiles.size()); 440 assertEquals("public registered profiles", 0, getPublicProfiles().size()); 441 FormDataMultiPart form = createFormData(RegistryTestHelper.getTestProfileContent()); 442 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")).type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form); 443 assertTrue(response.isProfile()); 444 assertTrue(response.isInUserSpace()); 445 ProfileDescription profileDesc = (ProfileDescription) response.getDescription(); 446 assertNotNull(profileDesc); 447 assertEquals("Test1", profileDesc.getName()); 448 assertEquals("My Test", profileDesc.getDescription()); 449 assertEquals(expectedUserId("JUnit@test.com"), profileDesc.getUserId()); 450 assertEquals("JUnit@test.com", profileDesc.getCreatorName()); 451 assertTrue(profileDesc.getId().startsWith(ComponentRegistry.REGISTRY_ID + "p_")); 452 assertNotNull(profileDesc.getRegistrationDate()); 453 assertEquals("http://localhost:9998/registry/profiles/" + profileDesc.getId() + "?userspace=true", profileDesc.getHref()); 454 455 profiles = getUserProfiles(); 456 assertEquals(1, profiles.size()); 457 assertEquals(0, getPublicProfiles().size()); 458 // Try get from public registry 459 ClientResponse cResponse = getResource().path("/registry/profiles/" + profileDesc.getId()).accept(MediaType.APPLICATION_XML).get( 460 ClientResponse.class); 461 // Should return 204 = no content 462 assertEquals(204, cResponse.getStatus()); 463 CMDComponentSpec spec = getAuthenticatedResource( 464 getResource().path("/registry/profiles/" + profileDesc.getId()).queryParam(USERSPACE_PARAM, "true")).accept( 465 MediaType.APPLICATION_XML).get(CMDComponentSpec.class); 466 assertNotNull(spec); 467 468 cResponse = getResource().path("/registry/profiles/" + profileDesc.getId() + "/xsd").accept(MediaType.TEXT_XML).get( 469 ClientResponse.class); 470 assertEquals(200, cResponse.getStatus()); 471 String profile = cResponse.getEntity(String.class); 472 assertTrue(profile.length() > 0); 473 474 profile = getAuthenticatedResource(getResource().path("/registry/profiles/" + profileDesc.getId() + "/xml")).accept( 475 MediaType.TEXT_XML).get(String.class); 476 assertTrue(profile.length() > 0); 477 478 cResponse = getAuthenticatedResource( 479 getResource().path("/registry/profiles/" + profileDesc.getId()).queryParam(USERSPACE_PARAM, "true")).delete( 480 ClientResponse.class); 481 assertEquals(200, cResponse.getStatus()); 482 483 profiles = getUserProfiles(); 484 assertEquals(0, profiles.size()); 471 485 } 472 486 473 487 private List<ProfileDescription> getPublicProfiles() { 474 488 return getAuthenticatedResource("/registry/profiles").accept(MediaType.APPLICATION_XML).get(PROFILE_LIST_GENERICTYPE); 475 489 } 476 490 477 491 private List<ProfileDescription> getUserProfiles() { 478 479 492 return getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")).accept( 493 MediaType.APPLICATION_XML).get(PROFILE_LIST_GENERICTYPE); 480 494 } 481 495 482 496 private FormDataMultiPart createFormData(Object content) { 483 497 return createFormData(content, "My Test"); 484 498 } 485 499 486 500 private FormDataMultiPart createFormData(Object content, String description) { 487 488 489 490 491 492 493 501 FormDataMultiPart form = new FormDataMultiPart(); 502 form.field(ComponentRegistryRestService.DATA_FORM_FIELD, content, MediaType.APPLICATION_OCTET_STREAM_TYPE); 503 form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "Test1"); 504 form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, description); 505 form.field(ComponentRegistryRestService.DOMAIN_FORM_FIELD, "My domain"); 506 form.field(ComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup"); 507 return form; 494 508 } 495 509 496 510 @Test 497 511 public void testRegisterWithUserComponents() throws Exception { 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 512 ComponentRegistry userRegistry = componentRegistryFactory.getComponentRegistry(true, DummyPrincipal.DUMMY_CREDENTIALS); 513 String content = ""; 514 content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; 515 content += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; 516 content += " <Header/>\n"; 517 content += " <CMD_Component name=\"XXX\" CardinalityMin=\"1\" CardinalityMax=\"10\">\n"; 518 content += " <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n"; 519 content += " </CMD_Component>\n"; 520 content += "</CMD_ComponentSpec>\n"; 521 ComponentDescription compDesc1 = RegistryTestHelper.addComponent(userRegistry, "XXX1", content); 522 523 content = ""; 524 content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; 525 content += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; 526 content += " <Header/>\n"; 527 content += " <CMD_Component name=\"YYY\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n"; 528 content += " <CMD_Component ComponentId=\"" + compDesc1.getId() + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n"; 529 content += " </CMD_Component>\n"; 530 content += " </CMD_Component>\n"; 531 content += "</CMD_ComponentSpec>\n"; 532 FormDataMultiPart form = createFormData(content); 533 RegisterResponse response = getAuthenticatedResource("/registry/components").type(MediaType.MULTIPART_FORM_DATA).post( 534 RegisterResponse.class, form); 535 assertFalse(response.isRegistered()); 536 assertEquals(1, response.getErrors().size()); 537 assertEquals("referenced component cannot be found in the published components: " + compDesc1.getName() + " (" + compDesc1.getId() 538 + ")", response.getErrors().get(0)); 539 540 response = getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")).type( 541 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form); 542 assertTrue(response.isRegistered()); 543 ComponentDescription comp2 = (ComponentDescription) response.getDescription(); 544 545 content = ""; 546 content += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; 547 content += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; 548 content += " <Header/>\n"; 549 content += " <CMD_Component name=\"ZZZ\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n"; 550 content += " <CMD_Component ComponentId=\"" + comp2.getId() + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n"; 551 content += " </CMD_Component>\n"; 552 content += " </CMD_Component>\n"; 553 content += "</CMD_ComponentSpec>\n"; 554 555 form = createFormData(content); 556 response = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form); 557 assertFalse(response.isRegistered()); 558 assertEquals(1, response.getErrors().size()); 559 assertEquals("referenced component cannot be found in the published components: " + comp2.getName() + " (" + comp2.getId() + ")", 560 response.getErrors().get(0)); 561 562 response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")).type( 563 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form); 564 assertTrue(response.isRegistered()); 551 565 } 552 566 553 567 @Test 554 568 public void testRegisterUserspaceComponent() throws Exception { 555 List<ComponentDescription> components = getUserComponents(); 556 assertEquals("user registered components", 0, components.size()); 557 assertEquals("public registered components", 0, getPublicComponents().size()); 558 FormDataMultiPart form = createFormData(RegistryTestHelper.getComponentTestContent()); 559 560 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")) 561 .type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form); 562 assertTrue(response.isRegistered()); 563 assertFalse(response.isProfile()); 564 assertTrue(response.isInUserSpace()); 565 ComponentDescription desc = (ComponentDescription) response.getDescription(); 566 assertNotNull(desc); 567 assertEquals("Test1", desc.getName()); 568 assertEquals("My Test", desc.getDescription()); 569 assertEquals(expectedUserId("JUnit@test.com"), desc.getUserId()); 570 assertEquals("JUnit@test.com", desc.getCreatorName()); 571 assertEquals("TestGroup", desc.getGroupName()); 572 assertTrue(desc.getId().startsWith(ComponentRegistry.REGISTRY_ID + "c_")); 573 assertNotNull(desc.getRegistrationDate()); 574 String url = getResource().getUriBuilder().build().toString(); 575 assertEquals(url + "registry/components/" + desc.getId() + "?userspace=true", desc.getHref()); 576 577 components = getUserComponents(); 578 assertEquals(1, components.size()); 579 assertEquals(0, getPublicComponents().size()); 580 581 // Try to get from public registry 582 ClientResponse cResponse = getResource().path("/registry/components/" + desc.getId()).accept(MediaType.APPLICATION_XML).get( 583 ClientResponse.class); 584 // Should return 204 = no content 585 assertEquals(204, cResponse.getStatus()); 586 CMDComponentSpec spec = getUserComponent(desc); 587 assertNotNull(spec); 588 589 cResponse = getResource().path("/registry/components/" + desc.getId() + "/xsd").accept(MediaType.TEXT_XML) 590 .get(ClientResponse.class); 591 assertEquals(200, cResponse.getStatus()); 592 String result = cResponse.getEntity(String.class); 593 assertTrue(result.length() > 0); 594 595 result = getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId() + "/xml")).accept(MediaType.TEXT_XML) 596 .get(String.class); 597 assertTrue(result.length() > 0); 598 599 cResponse = getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId()).queryParam(USERSPACE_PARAM, "true")) 600 .delete(ClientResponse.class); 601 assertEquals(200, cResponse.getStatus()); 602 603 components = getUserComponents(); 604 assertEquals(0, components.size()); 569 List<ComponentDescription> components = getUserComponents(); 570 assertEquals("user registered components", 0, components.size()); 571 assertEquals("public registered components", 0, getPublicComponents().size()); 572 FormDataMultiPart form = createFormData(RegistryTestHelper.getComponentTestContent()); 573 574 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")).type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form); 575 assertTrue(response.isRegistered()); 576 assertFalse(response.isProfile()); 577 assertTrue(response.isInUserSpace()); 578 ComponentDescription desc = (ComponentDescription) response.getDescription(); 579 assertNotNull(desc); 580 assertEquals("Test1", desc.getName()); 581 assertEquals("My Test", desc.getDescription()); 582 assertEquals(expectedUserId("JUnit@test.com"), desc.getUserId()); 583 assertEquals("JUnit@test.com", desc.getCreatorName()); 584 assertEquals("TestGroup", desc.getGroupName()); 585 assertTrue(desc.getId().startsWith(ComponentRegistry.REGISTRY_ID + "c_")); 586 assertNotNull(desc.getRegistrationDate()); 587 String url = getResource().getUriBuilder().build().toString(); 588 assertEquals(url + "registry/components/" + desc.getId() + "?userspace=true", desc.getHref()); 589 590 components = getUserComponents(); 591 assertEquals(1, components.size()); 592 assertEquals(0, getPublicComponents().size()); 593 594 // Try to get from public registry 595 ClientResponse cResponse = getResource().path("/registry/components/" + desc.getId()).accept(MediaType.APPLICATION_XML).get( 596 ClientResponse.class); 597 // Should return 204 = no content 598 assertEquals(204, cResponse.getStatus()); 599 CMDComponentSpec spec = getUserComponent(desc); 600 assertNotNull(spec); 601 602 cResponse = getResource().path("/registry/components/" + desc.getId() + "/xsd").accept(MediaType.TEXT_XML).get(ClientResponse.class); 603 assertEquals(200, cResponse.getStatus()); 604 String result = cResponse.getEntity(String.class); 605 assertTrue(result.length() > 0); 606 607 result = getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId() + "/xml")).accept(MediaType.TEXT_XML).get(String.class); 608 assertTrue(result.length() > 0); 609 610 cResponse = getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId()).queryParam(USERSPACE_PARAM, "true")).delete(ClientResponse.class); 611 assertEquals(200, cResponse.getStatus()); 612 613 components = getUserComponents(); 614 assertEquals(0, components.size()); 605 615 } 606 616 607 617 @Test 608 618 public void testUpdateComponent() throws Exception { 609 List<ComponentDescription> components = getUserComponents(); 610 assertEquals("user registered components", 0, components.size()); 611 assertEquals("public registered components", 0, getPublicComponents().size()); 612 613 FormDataMultiPart form = createFormData(RegistryTestHelper.getComponentTestContent()); 614 ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")) 615 .type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 616 assertEquals(ClientResponse.Status.OK.getStatusCode(), cResponse.getStatus()); 617 RegisterResponse response = cResponse.getEntity(RegisterResponse.class); 618 assertTrue(response.isRegistered()); 619 assertFalse(response.isProfile()); 620 assertTrue(response.isInUserSpace()); 621 ComponentDescription desc = (ComponentDescription) response.getDescription(); 622 assertNotNull(desc); 623 assertEquals("Test1", desc.getName()); 624 assertEquals("My Test", desc.getDescription()); 625 Date firstDate = AbstractDescription.getDate(desc.getRegistrationDate()); 626 CMDComponentSpec spec = getUserComponent(desc); 627 assertNotNull(spec); 628 assertEquals("Access", spec.getCMDComponent().get(0).getName()); 629 components = getUserComponents(); 630 assertEquals(1, components.size()); 631 assertEquals(0, getPublicComponents().size()); 632 633 //Now update 634 form = createFormData(RegistryTestHelper.getComponentTestContent("TESTNAME"), "UPDATE DESCRIPTION!"); 635 cResponse = getAuthenticatedResource( 636 getResource().path("/registry/components/" + desc.getId() + "/update").queryParam(USERSPACE_PARAM, "true")).type( 637 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 638 assertEquals(ClientResponse.Status.OK.getStatusCode(), cResponse.getStatus()); 639 response = cResponse.getEntity(RegisterResponse.class); 640 assertTrue(response.isRegistered()); 641 assertFalse(response.isProfile()); 642 assertTrue(response.isInUserSpace()); 643 desc = (ComponentDescription) response.getDescription(); 644 assertNotNull(desc); 645 assertEquals("Test1", desc.getName()); 646 assertEquals("UPDATE DESCRIPTION!", desc.getDescription()); 647 Date secondDate = AbstractDescription.getDate(desc.getRegistrationDate()); 648 assertTrue(firstDate.before(secondDate) || firstDate.equals(secondDate)); 649 650 spec = getUserComponent(desc); 651 assertNotNull(spec); 652 assertEquals("TESTNAME", spec.getCMDComponent().get(0).getName()); 653 components = getUserComponents(); 654 assertEquals(1, components.size()); 655 assertEquals(0, getPublicComponents().size()); 619 List<ComponentDescription> components = getUserComponents(); 620 assertEquals("user registered components", 0, components.size()); 621 assertEquals("public registered components", 0, getPublicComponents().size()); 622 623 FormDataMultiPart form = createFormData(RegistryTestHelper.getComponentTestContent()); 624 ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")).type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 625 assertEquals(ClientResponse.Status.OK.getStatusCode(), cResponse.getStatus()); 626 RegisterResponse response = cResponse.getEntity(RegisterResponse.class); 627 assertTrue(response.isRegistered()); 628 assertFalse(response.isProfile()); 629 assertTrue(response.isInUserSpace()); 630 ComponentDescription desc = (ComponentDescription) response.getDescription(); 631 assertNotNull(desc); 632 assertEquals("Test1", desc.getName()); 633 assertEquals("My Test", desc.getDescription()); 634 Date firstDate = AbstractDescription.getDate(desc.getRegistrationDate()); 635 CMDComponentSpec spec = getUserComponent(desc); 636 assertNotNull(spec); 637 assertEquals("Access", spec.getCMDComponent().get(0).getName()); 638 components = getUserComponents(); 639 assertEquals(1, components.size()); 640 assertEquals(0, getPublicComponents().size()); 641 642 //Now update 643 form = createFormData(RegistryTestHelper.getComponentTestContent("TESTNAME"), "UPDATE DESCRIPTION!"); 644 cResponse = getAuthenticatedResource( 645 getResource().path("/registry/components/" + desc.getId() + "/update").queryParam(USERSPACE_PARAM, "true")).type( 646 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 647 assertEquals(ClientResponse.Status.OK.getStatusCode(), cResponse.getStatus()); 648 response = cResponse.getEntity(RegisterResponse.class); 649 assertTrue(response.isRegistered()); 650 assertFalse(response.isProfile()); 651 assertTrue(response.isInUserSpace()); 652 desc = (ComponentDescription) response.getDescription(); 653 assertNotNull(desc); 654 assertEquals("Test1", desc.getName()); 655 assertEquals("UPDATE DESCRIPTION!", desc.getDescription()); 656 Date secondDate = AbstractDescription.getDate(desc.getRegistrationDate()); 657 assertTrue(firstDate.before(secondDate) || firstDate.equals(secondDate)); 658 659 spec = getUserComponent(desc); 660 assertNotNull(spec); 661 assertEquals("TESTNAME", spec.getCMDComponent().get(0).getName()); 662 components = getUserComponents(); 663 assertEquals(1, components.size()); 664 assertEquals(0, getPublicComponents().size()); 656 665 } 657 666 658 667 @Test 659 668 public void testUpdateProfile() throws Exception { 660 List<ProfileDescription> profiles = getUserProfiles(); 661 assertEquals(0, profiles.size()); 662 assertEquals(0, getPublicProfiles().size()); 663 664 FormDataMultiPart form = createFormData(RegistryTestHelper.getTestProfileContent()); 665 ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")) 666 .type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 667 assertEquals(ClientResponse.Status.OK.getStatusCode(), cResponse.getStatus()); 668 RegisterResponse response = cResponse.getEntity(RegisterResponse.class); 669 assertTrue(response.isRegistered()); 670 assertTrue(response.isProfile()); 671 assertTrue(response.isInUserSpace()); 672 ProfileDescription desc = (ProfileDescription) response.getDescription(); 673 assertNotNull(desc); 674 assertEquals("Test1", desc.getName()); 675 assertEquals("My Test", desc.getDescription()); 676 assertEquals("TestGroup", desc.getGroupName()); 677 Date firstDate = AbstractDescription.getDate(desc.getRegistrationDate()); 678 CMDComponentSpec spec = getUserProfile(desc); 679 assertNotNull(spec); 680 assertEquals("Actor", spec.getCMDComponent().get(0).getName()); 681 profiles = getUserProfiles(); 682 assertEquals(1, profiles.size()); 683 assertEquals(0, getPublicComponents().size()); 684 685 //Now update 686 form = createFormData(RegistryTestHelper.getTestProfileContent("TESTNAME"), "UPDATE DESCRIPTION!"); 687 cResponse = getAuthenticatedResource( 688 getResource().path("/registry/profiles/" + desc.getId() + "/update").queryParam(USERSPACE_PARAM, "true")).type( 689 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 690 assertEquals(ClientResponse.Status.OK.getStatusCode(), cResponse.getStatus()); 691 response = cResponse.getEntity(RegisterResponse.class); 692 assertTrue(response.isRegistered()); 693 assertTrue(response.isProfile()); 694 assertTrue(response.isInUserSpace()); 695 desc = (ProfileDescription) response.getDescription(); 696 assertNotNull(desc); 697 assertEquals("Test1", desc.getName()); 698 assertEquals("UPDATE DESCRIPTION!", desc.getDescription()); 699 Date secondDate = AbstractDescription.getDate(desc.getRegistrationDate()); 700 assertTrue(firstDate.before(secondDate) || firstDate.equals(secondDate)); 701 702 spec = getUserProfile(desc); 703 assertNotNull(spec); 704 assertEquals("TESTNAME", spec.getCMDComponent().get(0).getName()); 705 profiles = getUserProfiles(); 706 assertEquals(1, profiles.size()); 707 assertEquals(0, getPublicComponents().size()); 669 List<ProfileDescription> profiles = getUserProfiles(); 670 assertEquals(0, profiles.size()); 671 assertEquals(0, getPublicProfiles().size()); 672 673 FormDataMultiPart form = createFormData(RegistryTestHelper.getTestProfileContent()); 674 ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")).type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 675 assertEquals(ClientResponse.Status.OK.getStatusCode(), cResponse.getStatus()); 676 RegisterResponse response = cResponse.getEntity(RegisterResponse.class); 677 assertTrue(response.isRegistered()); 678 assertTrue(response.isProfile()); 679 assertTrue(response.isInUserSpace()); 680 ProfileDescription desc = (ProfileDescription) response.getDescription(); 681 assertNotNull(desc); 682 assertEquals("Test1", desc.getName()); 683 assertEquals("My Test", desc.getDescription()); 684 assertEquals("TestGroup", desc.getGroupName()); 685 Date firstDate = AbstractDescription.getDate(desc.getRegistrationDate()); 686 CMDComponentSpec spec = getUserProfile(desc); 687 assertNotNull(spec); 688 assertEquals("Actor", spec.getCMDComponent().get(0).getName()); 689 profiles = getUserProfiles(); 690 assertEquals(1, profiles.size()); 691 assertEquals(0, getPublicComponents().size()); 692 693 //Now update 694 form = createFormData(RegistryTestHelper.getTestProfileContent("TESTNAME"), "UPDATE DESCRIPTION!"); 695 cResponse = getAuthenticatedResource( 696 getResource().path("/registry/profiles/" + desc.getId() + "/update").queryParam(USERSPACE_PARAM, "true")).type( 697 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 698 assertEquals(ClientResponse.Status.OK.getStatusCode(), cResponse.getStatus()); 699 response = cResponse.getEntity(RegisterResponse.class); 700 assertTrue(response.isRegistered()); 701 assertTrue(response.isProfile()); 702 assertTrue(response.isInUserSpace()); 703 desc = (ProfileDescription) response.getDescription(); 704 assertNotNull(desc); 705 assertEquals("Test1", desc.getName()); 706 assertEquals("UPDATE DESCRIPTION!", desc.getDescription()); 707 Date secondDate = AbstractDescription.getDate(desc.getRegistrationDate()); 708 assertTrue(firstDate.before(secondDate) || firstDate.equals(secondDate)); 709 710 spec = getUserProfile(desc); 711 assertNotNull(spec); 712 assertEquals("TESTNAME", spec.getCMDComponent().get(0).getName()); 713 profiles = getUserProfiles(); 714 assertEquals(1, profiles.size()); 715 assertEquals(0, getPublicComponents().size()); 708 716 } 709 717 710 718 private CMDComponentSpec getUserComponent(ComponentDescription desc) { 711 return getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId()).queryParam(USERSPACE_PARAM, "true")) 712 .accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class); 719 return getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId()).queryParam(USERSPACE_PARAM, "true")).accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class); 713 720 } 714 721 715 722 private CMDComponentSpec getUserProfile(ProfileDescription desc) { 716 return getAuthenticatedResource(getResource().path("/registry/profiles/" + desc.getId()).queryParam(USERSPACE_PARAM, "true")) 717 .accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class); 723 return getAuthenticatedResource(getResource().path("/registry/profiles/" + desc.getId()).queryParam(USERSPACE_PARAM, "true")).accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class); 718 724 } 719 725 720 726 private List<ComponentDescription> getPublicComponents() { 721 727 return getAuthenticatedResource("/registry/components").accept(MediaType.APPLICATION_XML).get(COMPONENT_LIST_GENERICTYPE); 722 728 } 723 729 724 730 private List<ComponentDescription> getUserComponents() { 725 726 731 return getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")).accept( 732 MediaType.APPLICATION_XML).get(COMPONENT_LIST_GENERICTYPE); 727 733 } 728 734 729 735 @Test 730 736 public void testRegisterComponent() throws Exception { 731 FormDataMultiPart form = new FormDataMultiPart(); 732 form.field(ComponentRegistryRestService.DATA_FORM_FIELD, RegistryTestHelper.getComponentTestContent(), 733 MediaType.APPLICATION_OCTET_STREAM_TYPE); 734 form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "ComponentTest1"); 735 form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, "My Test Component"); 736 form.field(ComponentRegistryRestService.DOMAIN_FORM_FIELD, "TestDomain"); 737 form.field(ComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup"); 738 RegisterResponse response = getAuthenticatedResource("/registry/components").type(MediaType.MULTIPART_FORM_DATA).post( 739 RegisterResponse.class, form); 740 assertTrue(response.isRegistered()); 741 assertFalse(response.isProfile()); 742 assertFalse(response.isInUserSpace()); 743 ComponentDescription desc = (ComponentDescription) response.getDescription(); 744 assertNotNull(desc); 745 assertEquals("ComponentTest1", desc.getName()); 746 assertEquals("My Test Component", desc.getDescription()); 747 assertEquals(expectedUserId("JUnit@test.com"), desc.getUserId()); 748 assertEquals("JUnit@test.com", desc.getCreatorName()); 749 assertEquals("TestGroup", desc.getGroupName()); 750 assertEquals("TestDomain", desc.getDomainName()); 751 assertTrue(desc.getId().startsWith(ComponentRegistry.REGISTRY_ID + "c_")); 752 assertNotNull(desc.getRegistrationDate()); 753 String url = getResource().getUriBuilder().build().toString(); 754 assertEquals(url + "registry/components/" + desc.getId(), desc.getHref()); 737 FormDataMultiPart form = new FormDataMultiPart(); 738 form.field(ComponentRegistryRestService.DATA_FORM_FIELD, RegistryTestHelper.getComponentTestContent(), 739 MediaType.APPLICATION_OCTET_STREAM_TYPE); 740 form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "ComponentTest1"); 741 form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, "My Test Component"); 742 form.field(ComponentRegistryRestService.DOMAIN_FORM_FIELD, "TestDomain"); 743 form.field(ComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup"); 744 RegisterResponse response = getAuthenticatedResource("/registry/components").type(MediaType.MULTIPART_FORM_DATA).post( 745 RegisterResponse.class, form); 746 assertTrue(response.isRegistered()); 747 assertFalse(response.isProfile()); 748 assertFalse(response.isInUserSpace()); 749 ComponentDescription desc = (ComponentDescription) response.getDescription(); 750 assertNotNull(desc); 751 assertEquals("ComponentTest1", desc.getName()); 752 assertEquals("My Test Component", desc.getDescription()); 753 assertEquals(expectedUserId("JUnit@test.com"), desc.getUserId()); 754 assertEquals("JUnit@test.com", desc.getCreatorName()); 755 assertEquals("TestGroup", desc.getGroupName()); 756 assertEquals("TestDomain", desc.getDomainName()); 757 assertTrue(desc.getId().startsWith(ComponentRegistry.REGISTRY_ID + "c_")); 758 assertNotNull(desc.getRegistrationDate()); 759 String url = getResource().getUriBuilder().build().toString(); 760 assertEquals(url + "registry/components/" + desc.getId(), desc.getHref()); 761 } 762 763 @Test 764 public void testRegisterComment() throws Exception { 765 FormDataMultiPart form = new FormDataMultiPart(); 766 form.field(ComponentRegistryRestService.DATA_FORM_FIELD, RegistryTestHelper.getCommentTestContent(), 767 MediaType.APPLICATION_OCTET_STREAM_TYPE); 768 fillUp(); 769 RegisterResponse response = getAuthenticatedResource("/registry/profiles/clarin.eu:cr1:profile1/comments").type(MediaType.MULTIPART_FORM_DATA).post( 770 RegisterResponse.class, form); 771 assertFalse(response.isInUserSpace()); 772 Comment comment = (Comment) response.getComment(); 773 assertNotNull(comment); 774 assertEquals("CommentTest1", comment.getComment()); 775 assertEquals(expectedUserId("JUnit@test.com"), comment.getUserId()); 776 assertTrue(comment.getId().startsWith(ComponentRegistry.REGISTRY_ID + "p_")); 777 assertNotNull(comment.getCommentDate()); 778 String url = getResource().getUriBuilder().build().toString(); 779 assertEquals(url + "registry/profiles/{clarin.eu:cr1:p_1297242111880}/comments/" + comment.getId(), 1); 755 780 } 756 781 757 782 @Test 758 783 public void testRegisterProfileInvalidData() throws Exception { 759 760 761 762 763 764 765 766 767 768 769 770 771 772 784 FormDataMultiPart form = new FormDataMultiPart(); 785 String notAValidProfile = "<CMD_ComponentSpec> </CMD_ComponentSpec>"; 786 form.field(ComponentRegistryRestService.DATA_FORM_FIELD, new ByteArrayInputStream(notAValidProfile.getBytes()), 787 MediaType.APPLICATION_OCTET_STREAM_TYPE); 788 form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "ProfileTest1"); 789 form.field(ComponentRegistryRestService.DOMAIN_FORM_FIELD, "Domain"); 790 form.field(ComponentRegistryRestService.GROUP_FORM_FIELD, "Group"); 791 form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, "My Test Profile"); 792 RegisterResponse postResponse = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post( 793 RegisterResponse.class, form); 794 assertTrue(postResponse.isProfile()); 795 assertFalse(postResponse.isRegistered()); 796 assertEquals(1, postResponse.getErrors().size()); 797 assertTrue(postResponse.getErrors().get(0).contains("SAXParseException")); 773 798 } 774 799 775 800 @Test 776 801 public void testRegisterProfileInvalidDescriptionAndContent() throws Exception { 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 802 FormDataMultiPart form = new FormDataMultiPart(); 803 String profileContent = ""; 804 profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; 805 profileContent += "<CMD_ComponentSpec> \n"; //No isProfile attribute 806 profileContent += " <Header />\n"; 807 profileContent += " <CMD_Component name=\"Actor\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n"; 808 profileContent += " <AttributeList>\n"; 809 profileContent += " <Attribute>\n"; 810 profileContent += " <Name>Name</Name>\n"; 811 profileContent += " <Type>string</Type>\n"; 812 profileContent += " </Attribute>\n"; 813 profileContent += " </AttributeList>\n"; 814 profileContent += " </CMD_Component>\n"; 815 profileContent += "</CMD_ComponentSpec>\n"; 816 form.field("data", new ByteArrayInputStream(profileContent.getBytes()), MediaType.APPLICATION_OCTET_STREAM_TYPE); 817 form.field("name", "");//Empty name so invalid 818 form.field("description", "My Test Profile"); 819 RegisterResponse response = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post( 820 RegisterResponse.class, form); 821 assertFalse(response.isRegistered()); 822 assertEquals(2, response.getErrors().size()); 823 assertNotNull(response.getErrors().get(0)); 824 assertEquals(MDValidator.PARSE_ERROR, response.getErrors().get(1).substring(0, MDValidator.PARSE_ERROR.length())); 800 825 } 801 826 802 827 @Test 803 828 public void testRegisterComponentAsProfile() throws Exception { 804 FormDataMultiPart form = new FormDataMultiPart(); 805 form.field(ComponentRegistryRestService.DATA_FORM_FIELD, RegistryTestHelper.getComponentTestContent(), 806 MediaType.APPLICATION_OCTET_STREAM_TYPE); 807 form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "t"); 808 form.field(ComponentRegistryRestService.DOMAIN_FORM_FIELD, "domain"); 809 form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, "My Test"); 810 form.field(ComponentRegistryRestService.GROUP_FORM_FIELD, "My Group"); 811 RegisterResponse response = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post( 812 RegisterResponse.class, form); 813 assertFalse(response.isRegistered()); 814 assertTrue(response.isProfile()); 815 assertEquals(1, response.getErrors().size()); 816 assertEquals(MDValidator.MISMATCH_ERROR, response.getErrors().get(0)); 817 } 818 829 FormDataMultiPart form = new FormDataMultiPart(); 830 form.field(ComponentRegistryRestService.DATA_FORM_FIELD, RegistryTestHelper.getComponentTestContent(), 831 MediaType.APPLICATION_OCTET_STREAM_TYPE); 832 form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "t"); 833 form.field(ComponentRegistryRestService.DOMAIN_FORM_FIELD, "domain"); 834 form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, "My Test"); 835 form.field(ComponentRegistryRestService.GROUP_FORM_FIELD, "My Group"); 836 RegisterResponse response = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post( 837 RegisterResponse.class, form); 838 assertFalse(response.isRegistered()); 839 assertTrue(response.isProfile()); 840 assertEquals(1, response.getErrors().size()); 841 assertEquals(MDValidator.MISMATCH_ERROR, response.getErrors().get(0)); 842 } 819 843 } -
ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTestCase.java
r1419 r1635 7 7 8 8 import clarin.cmdi.componentregistry.impl.database.UserDao; 9 import clarin.cmdi.componentregistry.model.Comment; 9 10 import clarin.cmdi.componentregistry.model.ComponentDescription; 10 11 import clarin.cmdi.componentregistry.model.ProfileDescription; … … 33 34 }; 34 35 protected final static GenericType<List<ComponentDescription>> COMPONENT_LIST_GENERICTYPE = new GenericType<List<ComponentDescription>>() { 36 }; 37 protected final static GenericType<List<Comment>> COMMENT_LIST_GENERICTYPE = new GenericType<List<Comment>>() { 35 38 }; 36 39 -
ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/RegistryTestHelper.java
r1562 r1635 15 15 import clarin.cmdi.componentregistry.MDMarshaller; 16 16 import clarin.cmdi.componentregistry.components.CMDComponentSpec; 17 import clarin.cmdi.componentregistry.model.Comment; 17 18 import clarin.cmdi.componentregistry.model.ComponentDescription; 18 19 import clarin.cmdi.componentregistry.model.ProfileDescription; … … 28 29 29 30 public static ComponentDescription addComponent(ComponentRegistry testRegistry, String id) throws ParseException, JAXBException { 30 31 return addComponent(testRegistry, id, getComponentTestContent()); 31 32 } 32 33 33 34 public static ComponentDescription addComponent(ComponentRegistry testRegistry, String id, String content) throws ParseException, 34 35 35 JAXBException, UnsupportedEncodingException { 36 return addComponent(testRegistry, id, new ByteArrayInputStream(content.getBytes("UTF-8"))); 36 37 } 37 38 38 39 private static ComponentDescription addComponent(ComponentRegistry testRegistry, String id, InputStream content) throws ParseException, 39 40 41 42 43 44 45 46 47 48 49 40 JAXBException { 41 ComponentDescription desc = ComponentDescription.createNewDescription(); 42 desc.setCreatorName(DummyPrincipal.DUMMY_CREDENTIALS.getDisplayName()); 43 desc.setUserId(DummyPrincipal.DUMMY_CREDENTIALS.getPrincipalName()); 44 desc.setName(id); 45 desc.setDescription("Test Description"); 46 desc.setId(ComponentRegistry.REGISTRY_ID + id); 47 desc.setHref("link:" + ComponentRegistry.REGISTRY_ID + id); 48 CMDComponentSpec spec = MDMarshaller.unmarshal(CMDComponentSpec.class, content, MDMarshaller.getCMDComponentSchema()); 49 testRegistry.register(desc, spec); 50 return desc; 50 51 } 51 52 52 53 public static int updateComponent(ComponentRegistry testRegistry, ComponentDescription description, String content) throws JAXBException { 53 54 return testRegistry.update(description, getComponentFromString(content), DummyPrincipal.DUMMY_CREDENTIALS.getPrincipal(), true); 54 55 } 55 56 56 57 public static String getProfileTestContentString() { 57 58 return getProfileTestContentString("Actor"); 58 59 } 59 60 60 61 private static String getProfileTestContentString(String name) { 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 62 String profileContent = ""; 63 profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; 64 profileContent += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; 65 profileContent += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; 66 profileContent += " <Header />\n"; 67 profileContent += " <CMD_Component name=\"" + name + "\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n"; 68 profileContent += " <AttributeList>\n"; 69 profileContent += " <Attribute>\n"; 70 profileContent += " <Name>Name</Name>\n"; 71 profileContent += " <Type>string</Type>\n"; 72 profileContent += " </Attribute>\n"; 73 profileContent += " </AttributeList>\n"; 74 profileContent += " <CMD_Element name=\"Age\">\n"; 75 profileContent += " <ValueScheme>\n"; 76 profileContent += " <pattern>[23][0-9]</pattern>\n"; 77 profileContent += " </ValueScheme>\n"; 78 profileContent += " </CMD_Element>\n"; 79 profileContent += " </CMD_Component>\n"; 80 profileContent += "</CMD_ComponentSpec>\n"; 81 return profileContent; 81 82 } 82 83 83 84 public static InputStream getTestProfileContent() { 84 85 return getTestProfileContent("Actor"); 85 86 } 86 87 87 88 public static InputStream getTestProfileContent(String name) { 88 89 return new ByteArrayInputStream(getProfileTestContentString(name).getBytes()); 89 90 } 90 91 91 92 public static ProfileDescription addProfile(ComponentRegistry testRegistry, String id) throws ParseException, JAXBException { 92 93 return addProfile(testRegistry, id, RegistryTestHelper.getTestProfileContent()); 93 94 } 94 95 95 96 public static ProfileDescription addProfile(ComponentRegistry testRegistry, String id, String content) throws ParseException, 96 97 97 JAXBException { 98 return addProfile(testRegistry, id, new ByteArrayInputStream(content.getBytes())); 98 99 } 99 100 100 101 private static ProfileDescription addProfile(ComponentRegistry testRegistry, String id, InputStream content) throws ParseException, 101 102 103 104 105 106 107 108 109 110 111 102 JAXBException { 103 ProfileDescription desc = ProfileDescription.createNewDescription(); 104 desc.setCreatorName(DummyPrincipal.DUMMY_CREDENTIALS.getDisplayName()); 105 desc.setUserId(DummyPrincipal.DUMMY_CREDENTIALS.getPrincipalName()); 106 desc.setName(id); 107 desc.setDescription("Test Description"); 108 desc.setId(ComponentRegistry.REGISTRY_ID + id); 109 desc.setHref("link:" + ComponentRegistry.REGISTRY_ID + id); 110 CMDComponentSpec spec = MDMarshaller.unmarshal(CMDComponentSpec.class, content, MDMarshaller.getCMDComponentSchema()); 111 testRegistry.register(desc, spec); 112 return desc; 112 113 } 113 114 114 115 public static CMDComponentSpec getTestProfile() throws JAXBException { 115 116 return MDMarshaller.unmarshal(CMDComponentSpec.class, getTestProfileContent(), MDMarshaller.getCMDComponentSchema()); 116 117 } 117 118 118 119 public static String getComponentTestContentString() { 119 120 return getComponentTestContentString("Access"); 120 121 } 121 122 122 123 public static InputStream getComponentTestContent() { 123 124 return getComponentTestContent("Access"); 124 125 } 125 126 126 127 public static String getComponentTestContentString(String componentName) { 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 128 String compContent = ""; 129 compContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; 130 compContent += "\n"; 131 compContent += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; 132 compContent += " xsi:noNamespaceSchemaLocation=\"../../general-component-schema.xsd\">\n"; 133 compContent += " \n"; 134 compContent += " <Header/>\n"; 135 compContent += " \n"; 136 compContent += " <CMD_Component name=\"" + componentName + "\" CardinalityMin=\"1\" CardinalityMax=\"1\">\n"; 137 compContent += " <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n"; 138 compContent += " <CMD_Element name=\"Date\">\n"; 139 compContent += " <ValueScheme>\n"; 140 compContent += " <!-- matching dates of the pattern yyyy-mm-dd (ISO 8601); this only matches dates from the years 1000 through 2999 and does allow some invalid dates (e.g. February, the 30th) -->\n"; 141 compContent += " <pattern>(1|2)\\d{3}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])</pattern> \n"; 142 compContent += " </ValueScheme>\n"; 143 compContent += " </CMD_Element>\n"; 144 compContent += " <CMD_Element name=\"Owner\" ValueScheme=\"string\" />\n"; 145 compContent += " <CMD_Element name=\"Publisher\" ValueScheme=\"string\" />\n"; 146 compContent += " </CMD_Component>\n"; 147 compContent += "\n"; 148 compContent += "</CMD_ComponentSpec>\n"; 149 return compContent; 149 150 } 150 151 151 152 public static CMDComponentSpec getComponentFromString(String contentString) throws JAXBException { 152 153 return MDMarshaller.unmarshal(CMDComponentSpec.class, getComponentContent(contentString), MDMarshaller.getCMDComponentSchema()); 153 154 } 154 155 155 156 public static InputStream getComponentContent(String content) { 156 157 return new ByteArrayInputStream(content.getBytes()); 157 158 } 158 159 159 160 public static InputStream getComponentTestContent(String componentName) { 160 161 return getComponentContent(getComponentTestContentString(componentName)); 161 162 } 162 163 163 164 public static CMDComponentSpec getTestComponent() throws JAXBException { 164 165 return MDMarshaller.unmarshal(CMDComponentSpec.class, getComponentTestContent(), MDMarshaller.getCMDComponentSchema()); 165 166 } 166 167 167 168 public static CMDComponentSpec getTestComponent(String name) throws JAXBException { 168 169 return MDMarshaller.unmarshal(CMDComponentSpec.class, getComponentTestContent(name), MDMarshaller.getCMDComponentSchema()); 169 170 } 170 171 171 172 public static String getXml(CMDComponentSpec componentSpec) throws JAXBException, UnsupportedEncodingException { 172 ByteArrayOutputStream os = new ByteArrayOutputStream(); 173 MDMarshaller.marshal(componentSpec, os); 174 String xml = os.toString(); 175 try { 176 os.close(); 177 } catch (IOException ex) { 178 } 179 return xml; 173 ByteArrayOutputStream os = new ByteArrayOutputStream(); 174 MDMarshaller.marshal(componentSpec, os); 175 String xml = os.toString(); 176 try { 177 os.close(); 178 } catch (IOException ex) { 179 } 180 return xml; 181 } 182 183 public static Comment addComment(ComponentRegistry testRegistry, String id) throws ParseException, JAXBException { 184 return addComment(testRegistry, id, RegistryTestHelper.getCommentTestContent()); 185 } 186 187 // public static Comment addComment(ComponentRegistry testRegistry, String id, String content) throws ParseException, 188 // JAXBException { 189 // return addComment(testRegistry, id, new ByteArrayInputStream(content.getBytes())); 190 // } 191 192 private static Comment addComment(ComponentRegistry testRegistry, String id, InputStream content) throws ParseException, 193 JAXBException { 194 Comment com = Comment.createANewComment(); 195 com.setUserId(DummyPrincipal.DUMMY_CREDENTIALS.getPrincipalName()); 196 com.setId(id); 197 com.setComment("Test Comment"); 198 Comment spec = MDMarshaller.unmarshal(Comment.class, content, null); 199 testRegistry.registerComment(com, spec); 200 return com; 201 } 202 203 public static String getCommentTestContentString(String commentName) { 204 String comContent = ""; 205 comContent += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"; 206 comContent += "<comment xmlns:ns2=\"http://www.w3.org/1999/xlink\">\n"; 207 comContent += " <comments>"+ commentName +"</comments>\n"; 208 comContent += " <commentDate>myDate</commentDate>\n"; 209 comContent += " <profileDescriptionId>profile1</profileDescriptionId>\n"; 210 comContent += " <userId>8</userId>\n"; 211 comContent += " <id>1</id>\n"; 212 comContent += "</comment>\n"; 213 return comContent; 214 } 215 216 public static InputStream getTestCommentContent(String content) { 217 return new ByteArrayInputStream(getCommentTestContentString(content).getBytes()); 218 } 219 220 public static String getCommentTestContent(String commentName) { 221 return getCommentTestContentString("Actual"); 222 } 223 224 public static InputStream getCommentTestContent() { 225 return getTestCommentContent("Actual"); 180 226 } 181 227 … … 185 231 */ 186 232 public static boolean hasComponent(String xsd, String name, String min, String max) { 187 188 189 233 Pattern pattern = Pattern.compile("<xs:element name=\"" + name + "\" minOccurs=\"" + min + "\" maxOccurs=\"" + max + "\">"); 234 Matcher matcher = pattern.matcher(xsd); 235 return matcher.find() && !matcher.find(); //find only one 190 236 } 191 237 }
Note: See TracChangeset
for help on using the changeset viewer.