/** * The ContentItem MUST NOT allow to replace the main content part (the * Blob stored at index 0) */ @Test(expected=IllegalArgumentException.class) public void replaceMainPart() throws IOException{ ContentItem ci = createContentItem(contentSource); IRI mainPart = ci.getPartUri(0); ci.addPart(mainPart, new Date()); } @Test(expected=IllegalArgumentException.class)
/** * The ContentItem MUST NOT allow to replace the main content part (the * Blob stored at index 0) */ @Test(expected=IllegalArgumentException.class) public void replaceMainPart() throws IOException{ ContentItem ci = createContentItem(contentSource); IRI mainPart = ci.getPartUri(0); ci.addPart(mainPart, new Date()); } @Test(expected=IllegalArgumentException.class)
do { try { cpUri = ci.getPartUri(index); index++; try {
do { try { cpUri = ci.getPartUri(index); index++; try {
@Test(expected=IllegalStateException.class) public void removeMainContentPartByUri() throws IOException { ContentItem ci = createContentItem(contentSource); ci.removePart(ci.getPartUri(0)); } @Test(expected=IllegalStateException.class)
do { try { cpUri = ci.getPartUri(index); index++; try {
@Test(expected=IllegalStateException.class) public void removeMainContentPartByUri() throws IOException { ContentItem ci = createContentItem(contentSource); ci.removePart(ci.getPartUri(0)); } @Test(expected=IllegalStateException.class)
do { try { cpUri = ci.getPartUri(index); index++; try {
new StreamSource(entityStream, mediaType.toString())); parsedContentIds.add(contentItem.getPartUri(0).getUnicodeString());
new StreamSource(entityStream, mediaType.toString())); parsedContentIds.add(contentItem.getPartUri(0).getUnicodeString());
@Test public void removeRemoveByIndex() throws IOException { ContentItem ci = createContentItem(contentSource); IRI uri = new IRI("urn:content.part:remove.test"); ci.addPart(uri, new Date()); int index = -1; try { for(int i=0; index < 0; i++){ IRI partUri = ci.getPartUri(i); if(partUri.equals(uri)){ index = i; } } }catch (NoSuchPartException e) { assertFalse("The part with the uri "+uri+" was not added correctly", true); } ci.removePart(index); try { ci.getPart(index, Date.class); assertTrue("The part with the uri "+uri+" was not removed correctly", false); }catch (NoSuchPartException e) { // expected } }
@Test public void removeRemoveByIndex() throws IOException { ContentItem ci = createContentItem(contentSource); IRI uri = new IRI("urn:content.part:remove.test"); ci.addPart(uri, new Date()); int index = -1; try { for(int i=0; index < 0; i++){ IRI partUri = ci.getPartUri(i); if(partUri.equals(uri)){ index = i; } } }catch (NoSuchPartException e) { assertFalse("The part with the uri "+uri+" was not added correctly", true); } ci.removePart(index); try { ci.getPart(index, Date.class); assertTrue("The part with the uri "+uri+" was not removed correctly", false); }catch (NoSuchPartException e) { // expected } }
@Test public void addingAndRetrieving() throws IOException{ ContentItem ci = createContentItem(contentSource); assertNotNull(ci); assertNotNull(ci.getUri()); IRI partUri = new IRI("http://foo/"); Date someObject = new Date(); ci.addPart(partUri, someObject); ci.getMetadata().add(new TripleImpl(ci.getUri(), new IRI("http://example.org/ontology#hasPart"), partUri)); ci.getMetadata().add(new TripleImpl(partUri, new IRI("http://example.org/ontology#isPartOf"),ci.getUri())); assertEquals(someObject, ci.getPart(partUri, Date.class)); assertEquals(someObject, ci.getPart(1, Date.class)); assertEquals(partUri, ci.getPartUri(1)); assertEquals(new IRI(ci.getUri().getUnicodeString()+"_main"), ci.getPartUri(0)); try { ci.getPart(2, Object.class); assertTrue("Requesting non existance part MUST throw an NoSuchPartException", false); } catch (NoSuchPartException e) {/* expected*/} try { ci.getPart(new IRI("http://foo/nonexisting"), Object.class); assertTrue("Requesting non existance part MUST throw an NoSuchPartException", false); } catch (NoSuchPartException e) {/* expected*/} try { ci.getPartUri(2); assertTrue("Requesting non existance part MUST throw an NoSuchPartException", false); } catch (NoSuchPartException e) {/* expected*/} //finally log the toString log.info("toString: {}",ci); } @Test(expected=IllegalArgumentException.class)
@Test public void addingAndRetrieving() throws IOException{ ContentItem ci = createContentItem(contentSource); assertNotNull(ci); assertNotNull(ci.getUri()); IRI partUri = new IRI("http://foo/"); Date someObject = new Date(); ci.addPart(partUri, someObject); ci.getMetadata().add(new TripleImpl(ci.getUri(), new IRI("http://example.org/ontology#hasPart"), partUri)); ci.getMetadata().add(new TripleImpl(partUri, new IRI("http://example.org/ontology#isPartOf"),ci.getUri())); assertEquals(someObject, ci.getPart(partUri, Date.class)); assertEquals(someObject, ci.getPart(1, Date.class)); assertEquals(partUri, ci.getPartUri(1)); assertEquals(new IRI(ci.getUri().getUnicodeString()+"_main"), ci.getPartUri(0)); try { ci.getPart(2, Object.class); assertTrue("Requesting non existance part MUST throw an NoSuchPartException", false); } catch (NoSuchPartException e) {/* expected*/} try { ci.getPart(new IRI("http://foo/nonexisting"), Object.class); assertTrue("Requesting non existance part MUST throw an NoSuchPartException", false); } catch (NoSuchPartException e) {/* expected*/} try { ci.getPartUri(2); assertTrue("Requesting non existance part MUST throw an NoSuchPartException", false); } catch (NoSuchPartException e) {/* expected*/} //finally log the toString log.info("toString: {}",ci); } @Test(expected=IllegalArgumentException.class)
parsedContentParts.add(contentItem.getPartUri(0).getUnicodeString()); return contentItem;
parsedContentParts.add(contentItem.getPartUri(0).getUnicodeString()); return contentItem;