Skip to content

Commit

Permalink
#182 - add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Nov 25, 2018
1 parent d1031aa commit 9e178bf
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,52 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.function.Consumer;

import org.hamcrest.core.IsEqual;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

public class SiteLoadTest {


@Test
public void loadFromYAML() throws Exception {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());

try( InputStream is = getClass().getClassLoader().getResourceAsStream("site.yaml") ) {
@Rule
public ExpectedException thrown = ExpectedException.none();

private void loadFromYAML( String resource, Consumer<Site> c ) throws Exception {
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());

try( InputStream is = getClass().getClassLoader().getResourceAsStream(resource) ) {
Site site = mapper.readValue( is, Site.class );

assertThat( site, notNullValue());

Path basedir = Paths.get("/tmp");
c.accept(site);
}

}

@Test
public void testIssue182() throws Exception {

//thrown.expect(Exception.class);
thrown.expect(JsonMappingException.class);
//thrown.expectMessage("name [page 1 ] is not valid!");
loadFromYAML( "site-issue182.yaml", site -> {

});

}

@Test
public void testLoadFromYAML() throws Exception {

loadFromYAML( "site.yaml", site -> {

final Path basedir = Paths.get("/tmp");
site.setBasedir( basedir );

assertThat( site.getHome(), notNullValue());
Expand All @@ -42,7 +69,8 @@ public void loadFromYAML() throws Exception {

assertThat( attachments, notNullValue());
assertThat( attachments.size(), equalTo( 1 ) );
}


});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,33 @@

import static org.bsc.confluence.model.SiteProcessor.processMarkdown;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.containsString;

import java.io.IOException;
import java.io.InputStream;
import java.util.regex.Pattern;

import org.apache.commons.io.IOUtils;
import org.hamcrest.core.IsNull;
import org.junit.Test;

public class SiteTest {

@Test
public void validateName() {

final Pattern p = Pattern.compile("^(.*)\\s+$|^\\s+(.*)");
assertThat( p.matcher("name").matches(), is(false));
assertThat( p.matcher("name ").matches(), is(true));
assertThat( p.matcher("name ").matches(), is(true));
assertThat( p.matcher(" name").matches(), is(true));
assertThat( p.matcher(" name").matches(), is(true));
assertThat( p.matcher(" name ").matches(), is(true));
assertThat( p.matcher(" name ").matches(), is(true));
}

@Test
public void shouldSupportReferenceNode() throws IOException {
final InputStream stream = getClass().getClassLoader().getResourceAsStream("withRefLink.md");
Expand Down
24 changes: 24 additions & 0 deletions maven-confluence-core/src/test/resources/site-issue182.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#site:
home:
uri: encoding.confluence
children:
- name: "page 1 "
uri: page1.md
- name: "page 2"
uri: page2.md
attachments:
- name: "attach1.png"
uri: attach1.png
comment: attach1_comment
contentType: "image/png"
version: 1
attachments:
- name: " home.png"
uri: home.png
comment: home_comment
contentType: "image/png"
version: 1
labels:
- encoding
- test

0 comments on commit 9e178bf

Please sign in to comment.