Skip to content

Commit

Permalink
Merge pull request #1 from mox601/master
Browse files Browse the repository at this point in the history
fixed bug for null fields, some file ignores, added slf4j dependency, and test
  • Loading branch information
simonetripodi committed Nov 28, 2012
2 parents bdad6da + b041fab commit 7706caa
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@
ehthumbs.db
Icon?
Thumbs.db

# target folders are ignored #
######################
annotations/target/*
core/target/*
59 changes: 52 additions & 7 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ THE SOFTWARE.

<name>Be3 :: Core</name>

<properties>
<sesame.version>2.3.2</sesame.version>
<log4j.version>1.2.15</log4j.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.99soft.be3</groupId>
Expand All @@ -45,37 +60,67 @@ THE SOFTWARE.
<dependency>
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-model</artifactId>
<version>2.3.2</version>
<version>${sesame.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-query</artifactId>
<version>2.3.2</version>
<version>${sesame.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-repository-sail</artifactId>
<version>2.3.2</version>
<version>${sesame.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-sail-memory</artifactId>
<version>2.3.2</version>
<version>${sesame.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-rio-rdfxml</artifactId>
<version>2.3.2</version>
<version>${sesame.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
<!--<version>1.6.1</version>-->
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<version>${log4j.version}</version>
<exclusions>
<exclusion>
<groupId>com.sun.jdmk</groupId>
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/java/org/nnsoft/be3/DefaultTypedBe3Impl.java
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,10 @@ private void addStatement(URI s, URI p, URI o, HashSet<Statement> added) {

private void addStatement(URI s, URI p, Object object, HashSet<Statement> added)
throws TypeHandlerRegistryException {
Statement statement = typeHandlerRegistry.getStatement(s, p, object);
added.add(statement);
if (object != null) {
Statement statement = typeHandlerRegistry.getStatement(s, p, object);
added.add(statement);
}
}

private URI getRDFType(Class beanClass) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/log4j.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.R=org.apache.log4j.RollingFileAppender

# Rollingfile appender config
log4j.appender.R.File=logs/collective-rdfizer.log
log4j.appender.R.File=logs/be3.log
log4j.appender.R.MaxFileSize=1000KB
# Keep five backup files
log4j.appender.R.MaxBackupIndex=5
Expand Down
68 changes: 45 additions & 23 deletions core/src/test/java/org/nnsoft/be3/TypedRDFizerTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@
*/
package org.nnsoft.be3;

import static org.nnsoft.be3.model.nested.Author.AuthorBuilder.author;
import static org.nnsoft.be3.model.nested.Page.PageBuilder.page;
import static org.testng.Assert.*;

import org.nnsoft.be3.annotations.RDFClassType;
import org.nnsoft.be3.model.Person;
import org.nnsoft.be3.model.hierarchy.EnhancedResource;
import org.nnsoft.be3.model.nested.Author;
import org.nnsoft.be3.model.nested.Book;
import org.nnsoft.be3.model.nested.Page;
import org.nnsoft.be3.model.nested.SimpleBook;
import static org.nnsoft.be3.model.nested.SimpleBook.SimpleBookBuilder.simpleBook;
import static org.nnsoft.be3.model.nested.Book.BookBuilder.book;
import org.nnsoft.be3.typehandler.*;
import org.openrdf.model.Statement;
import org.openrdf.model.URI;
Expand Down Expand Up @@ -177,7 +180,7 @@ public void shouldSerializeSimpleNestedObjects() throws RDFizerException {
// logger.debug("simpleBook statement: " + st);
// }

assertEquals(statements.size(), 7);
assertEquals(statements.size(), 9);
//TODO: test more things?
}

Expand All @@ -202,6 +205,27 @@ public void shouldAnnotateChildClassAndNotExtendedClass() throws RDFizerExceptio
);
}

@Test
public void shouldSerializeObjectSkippingNullFields() throws RDFizerException {
Long pageId = 45L;
Page pageWithNullContent = Page.PageBuilder.page()
.withNumber(pageId)
.havingContent(null)
.build();
assertNull(pageWithNullContent.getContent());
b3.serialize(pageWithNullContent, System.out, Format.RDFXML);
List<Statement> statements = b3.getRDFStatements(pageWithNullContent);

Page retrievedPageWithNullField = (Page) b3.getObject(
statements,
new URIImpl(getIdentifierURI(Page.class).toString() + "/" + pageWithNullContent.getNumber()),
Page.class
);

assertNull(retrievedPageWithNullField.getContent());
assertEquals(retrievedPageWithNullField.getNumber(), pageId);
}

private EnhancedResource getEnhancedResource() {
EnhancedResource enhancedResource = new EnhancedResource();
enhancedResource.setId(new Long(1));
Expand All @@ -218,34 +242,32 @@ private EnhancedResource getEnhancedResource() {
}

public SimpleBook getSimpleBook() {
SimpleBook simpleBook = new SimpleBook(1);
Author author = new Author(2);
Author author3 = new Author(3);
Author author4 = new Author(4);

simpleBook.setMainAuthor(author);
simpleBook.addAuthor(author3);
simpleBook.addAuthor(author4);
SimpleBook simpleBook = simpleBook()
.withId(1)
.withMainAuthor(author().withId(1).build())
.addAuthor(author().withId(2).build())
.addAuthor(author().withId(3).build())
.addAuthor(author().withId(4).build())
.build();
return simpleBook;
}

public Book getBook() {
Page first = new Page();
first.setNumber(new Long(1));
first.setContent("first page content");

Page second = new Page();
second.setNumber(new Long(2));
second.setContent("second page content");

Book book = new Book();
book.setId(new Long(1));
book.setTitle("book title");
book.addPage(first);
book.addPage(second);
Book book = book()
.withId(new Long(1))
.withTitle("book title")
.havingPage(page()
.withNumber(new Long(1))
.havingContent("first page content")
.build())
.havingPage(page()
.withNumber(new Long(2))
.havingContent("second page content")
.build())
.build();

return book;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ public class EnhancedResource extends SimpleResource {

private List<URI> topics = new ArrayList<URI>();

@Override
@RDFIdentifier
public Long getId() {
return super.getId();
}

@Override
@RDFProperty(properties = { "http://collective.com/profile/EnhancedResource/title" })
public String getTitle() {
return super.getTitle();
Expand Down
25 changes: 25 additions & 0 deletions core/src/test/java/org/nnsoft/be3/model/nested/Author.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class Author {

private int id;

public Author() {}

@RDFIdentifier
public int getId() {
return this.id;
Expand All @@ -44,4 +46,27 @@ public void setId(int id) {
public Author(int id) {
this.id = id;
}

public static class AuthorBuilder {

private Author author = new Author();

public static AuthorBuilder author() {
return new AuthorBuilder();
}

public AuthorBuilder withId(int id) {
author.setId(id);
return this;
}

public Author build() {
validate();
return author;
}

private void validate() {
//validate stuff
}
}
}
33 changes: 33 additions & 0 deletions core/src/test/java/org/nnsoft/be3/model/nested/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,37 @@ public int hashCode() {
result = 31 * result + (author != null ? author.hashCode() : 0);
return result;
}

public static class BookBuilder {

private Book book = new Book();

public static BookBuilder book() {
return new BookBuilder();
}

public BookBuilder withId(Long aLong) {
book.setId(aLong);
return this;
}

public Book build() {
validate();
return book;
}

public BookBuilder withTitle(String s) {
book.setTitle(s);
return this;
}

private void validate() {
//
}

public BookBuilder havingPage(Page page) {
book.addPage(page);
return this;
}
}
}
29 changes: 29 additions & 0 deletions core/src/test/java/org/nnsoft/be3/model/nested/Page.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,33 @@ public int hashCode() {
result = 31 * result + (content != null ? content.hashCode() : 0);
return result;
}

public static class PageBuilder {

private Page page = new Page();

public static PageBuilder page() {
return new PageBuilder();
}

public PageBuilder withNumber(Long pageNumber) {
page.setNumber(pageNumber);
return this;
}

public PageBuilder havingContent(String content) {
page.setContent(content);
return this;
}

public Page build() {
validate();
return page;
}

private void validate() {
//
}

}
}
Loading

0 comments on commit 7706caa

Please sign in to comment.