@Test public void testPLFM_1288() throws Exception { Project p = new Project(); p.setName("Create without entity type"); p.setEntityType(p.getClass().getName()); p = (Project) entityServletHelper.createEntity(p, TEST_USER1); toDelete.add(p.getId()); Study one = new Study(); one.setName("one"); one.setParentId(p.getId()); one.setEntityType(Study.class.getName()); one = (Study) entityServletHelper.createEntity(one, TEST_USER1); // Now try to re-use the name Code two = new Code(); two.setName("code"); two.setParentId(one.getId()); two.setEntityType(Code.class.getName()); try { two = (Code) entityServletHelper.createEntity(two, TEST_USER1); fail("Code cannot have a parent of type Study"); } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); assertTrue(e.getMessage().indexOf(Code.class.getName()) > 0); assertTrue(e.getMessage().indexOf(Study.class.getName()) > 0); } }
/** @throws java.lang.Exception */ @Before public void setUp() throws Exception { testHelper.setUp(); testHelper.setTestUser(TEST_USER1); project = new Project(); project.setName("proj"); project = testHelper.createEntity(project, null); dataset = new Study(); dataset.setName("study"); dataset.setParentId(project.getId()); dataset = testHelper.createEntity(dataset, null); // Add a public read ACL to the project object AccessControlList projectAcl = testHelper.getEntityACL(project); ResourceAccess ac = new ResourceAccess(); UserGroup authenticatedUsers = userGroupDAO.findGroup( AuthorizationConstants.DEFAULT_GROUPS.AUTHENTICATED_USERS.name(), false); assertNotNull(authenticatedUsers); ac.setPrincipalId(Long.parseLong(authenticatedUsers.getId())); ac.setAccessType(new HashSet<ACCESS_TYPE>()); ac.getAccessType().add(ACCESS_TYPE.READ); projectAcl.getResourceAccess().add(ac); projectAcl = testHelper.updateEntityAcl(project, projectAcl); testUser = userGroupDAO.findGroup(TEST_USER1, true); }
/** @throws Exception */ @Test public void testCreateS3TokenAbsolutePath() throws Exception { Data layer = new Data(); layer.setParentId(dataset.getId()); layer.setType(LayerTypeNames.E); layer = testHelper.createEntity(layer, null); // an absolute path to a file String initialPath = "/data/123.zip"; S3Token token = new S3Token(); token.setPath(initialPath); token.setMd5(TEST_MD5); token = testHelper.createObject(layer.getS3Token(), token); assertEquals(StackConfiguration.getS3Bucket(), token.getBucket()); assertTrue( token .getPath() .matches("^/" + KeyFactory.stringToKey(layer.getId()) + "/\\d+" + initialPath + "$")); assertEquals(TEST_MD5, token.getMd5()); assertEquals("application/zip", token.getContentType()); assertNotNull(token.getSecretAccessKey()); assertNotNull(token.getAccessKeyId()); assertNotNull(token.getSessionToken()); assertTrue(token.getPresignedUrl().matches("^http.*" + initialPath + ".*")); }
/** @throws Exception */ @Test public void testCreateS3TokenInsufficientPermissions() throws Exception { String initialPath = "foo.java"; S3Token token = new S3Token(); token.setPath(initialPath); token.setMd5(TEST_MD5); token = testHelper.createObject(dataset.getUri() + "/" + UrlHelpers.S3TOKEN, token); testHelper.setTestUser(TEST_USER2); try { token = testHelper.createObject(dataset.getUri() + "/" + UrlHelpers.S3TOKEN, token); fail("expected exception not thrown"); } catch (ServletTestHelperException ex) { assertTrue( ex.getMessage().startsWith("update access is required to obtain an S3Token for entity")); assertEquals(HttpStatus.FORBIDDEN.value(), ex.getHttpStatus()); } }
@Test(expected = NameConflictException.class) public void testPLFM_449NameConflict() throws Exception { Project p = new Project(); p.setName("Create without entity type"); p.setEntityType(p.getClass().getName()); p = (Project) entityServletHelper.createEntity(p, TEST_USER1); toDelete.add(p.getId()); Study one = new Study(); one.setName("one"); one.setParentId(p.getId()); one.setEntityType(Study.class.getName()); one = (Study) entityServletHelper.createEntity(one, TEST_USER1); // Now try to re-use the name Study two = new Study(); two.setName("one"); two.setParentId(p.getId()); two.setEntityType(Study.class.getName()); two = (Study) entityServletHelper.createEntity(two, TEST_USER1); }