Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Fixed NodeAssert property value assertions (assert messages) #5

Merged
merged 1 commit into from
Aug 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/com/ixxus/alfresco/NodeAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public NodeAssert doesNotHaveAspect(final QName aspect) {
public NodeAssert hasPropertyValue(final QName property, final Serializable expectedValue) {
exists();
final Serializable actualValue = nodeService.getProperty(this.actual, property);
Assertions.assertThat(expectedValue).isEqualTo(actualValue);
Assertions.assertThat(actualValue).isEqualTo(expectedValue);
return this;
}

Expand All @@ -183,7 +183,7 @@ public NodeAssert hasPropertyValue(final QName property, final Serializable expe
public NodeAssert doesNotHavePropertyValue(final QName property, final Serializable expectedValue) {
exists();
final Serializable actualValue = nodeService.getProperty(this.actual, property);
Assertions.assertThat(expectedValue).isNotEqualTo(actualValue);
Assertions.assertThat(actualValue).isNotEqualTo(expectedValue);
return this;
}

Expand Down
46 changes: 33 additions & 13 deletions src/test/java/com/ixxus/alfresco/NodeAssertTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ public class NodeAssertTest extends AbstractServiceTest {
@Before
public void setUp() {
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
String nodeName = "NodeAssertTest-" + UUID.randomUUID();
PropertyMap propertyMap = new PropertyMap();
final String nodeName = "NodeAssertTest-" + UUID.randomUUID();
final PropertyMap propertyMap = new PropertyMap();
propertyMap.put(ContentModel.PROP_NAME, nodeName);
nodeRef = nodeService.createNode(repository.getCompanyHome(), ContentModel.ASSOC_CONTAINS, QName.createQName(ContentModel.USER_MODEL_URI, nodeName),
ContentModel.TYPE_CONTENT, propertyMap).getChildRef();
ContentModel.TYPE_CONTENT, propertyMap).getChildRef();
}

@After
public void tearDown() {
if (nodeRef != null && nodeService.exists(nodeRef)) {
if ((nodeRef != null) && nodeService.exists(nodeRef)) {
nodeService.deleteNode(nodeRef);
}
}
Expand Down Expand Up @@ -139,12 +139,32 @@ public void test_has_property_value() {
assertThat(nodeRef).hasPropertyValue(ContentModel.PROP_COMPANYEMAIL, "my@email.com");
}

@Test
public void test_has_property_value_fails_with_correct_error_message() {
final String errorMsg = "expected:<\"my@[other]mail.com\"> but was:<\"my@[e]mail.com\">";
exception.expect(AssertionError.class);
exception.expectMessage(errorMsg);

nodeService.setProperty(nodeRef, ContentModel.PROP_COMPANYEMAIL, "my@email.com");
assertThat(nodeRef).hasPropertyValue(ContentModel.PROP_COMPANYEMAIL, "my@othermail.com");
}

@Test
public void test_does_not_have_property_value() {
nodeService.setProperty(nodeRef, ContentModel.PROP_COMPANYEMAIL, "my@email.com");
assertThat(nodeRef).doesNotHavePropertyValue(ContentModel.PROP_COMPANYEMAIL, "my@othermail.com");
}

@Test
public void test_does_not_have_property_value_fails_with_correct_error_message() {
final String errorMsg = "\nExpecting:\n <\"my@email.com\">\nnot to be equal to:\n <\"my@email.com\">";
exception.expect(AssertionError.class);
exception.expectMessage(errorMsg);

nodeService.setProperty(nodeRef, ContentModel.PROP_COMPANYEMAIL, "my@email.com");
assertThat(nodeRef).doesNotHavePropertyValue(ContentModel.PROP_COMPANYEMAIL, "my@email.com");
}

@Test(expected = AssertionError.class)
public void test_failed_property_value_test() {
nodeService.setProperty(nodeRef, ContentModel.PROP_COMPANYEMAIL, "my@email.com");
Expand All @@ -154,18 +174,18 @@ public void test_failed_property_value_test() {
@Test
public void test_property_starts_with() {
nodeService.setProperty(nodeRef, ContentModel.PROP_COMPANYEMAIL, "myname@email.com");
Condition<Serializable> startsWithMe = new Condition<>(value -> ((String) value).startsWith("myname"), "Should start with 'myname'");
final Condition<Serializable> startsWithMe = new Condition<>(value -> ((String) value).startsWith("myname"), "Should start with 'myname'");
assertThat(nodeRef).propertyValue(ContentModel.PROP_COMPANYEMAIL, startsWithMe);
}

@Test
public void test_property_not_starts_with() {
String errorMsg = "Should start with 'myname'";
final String errorMsg = "Should start with 'myname'";
exception.expect(AssertionError.class);
exception.expectMessage(errorMsg);
//
nodeService.setProperty(nodeRef, ContentModel.PROP_COMPANYEMAIL, "someoneelse@email.com");
Condition<Serializable> startsWithMe = new Condition<>(value -> ((String) value).startsWith("myname"), errorMsg);
final Condition<Serializable> startsWithMe = new Condition<>(value -> ((String) value).startsWith("myname"), errorMsg);
//
assertThat(nodeRef).propertyValue(ContentModel.PROP_COMPANYEMAIL, startsWithMe);
}
Expand Down Expand Up @@ -240,42 +260,42 @@ public void ensure_node_without_content_throws_exception() {

@Test(expected = AssertionError.class)
public void ensure_node_with_empty_content_throws_exception() {
ContentWriter w = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
final ContentWriter w = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
w.putContent("");
assertThat(nodeRef).hasContent(ContentModel.PROP_CONTENT);
}

@Test
public void ensure_node_with_content_does_not_throw_exception() {
ContentWriter w = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
final ContentWriter w = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
w.putContent("content");
assertThat(nodeRef).hasContent(ContentModel.PROP_CONTENT);
}

@Test
public void ensure_node_has_content() {
ContentWriter w = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
final ContentWriter w = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
w.putContent("content");
assertThat(nodeRef).hasContent("content");
}

@Test(expected = AssertionError.class)
public void ensure_node_with_different_content_throws_exception() {
ContentWriter w = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
final ContentWriter w = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
w.putContent("content");
assertThat(nodeRef).hasContent("different content");
}

@Test
public void ensure_node_content_contains_our_string() {
ContentWriter w = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
final ContentWriter w = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
w.putContent("my custom content");
assertThat(nodeRef).containsContent("custom");
}

@Test(expected = AssertionError.class)
public void ensure_node_content_that_does_not_contain_our_string_throws_exception() {
ContentWriter w = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
final ContentWriter w = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
w.putContent("content");
assertThat(nodeRef).containsContent("different content");
}
Expand Down