Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

DTOsProvider.Enc put() Method with Appendable or OutputStream as parameter does not work as expected #71

Closed
mcurcija opened this issue Nov 19, 2016 · 3 comments

Comments

@mcurcija
Copy link
Contributor

Expected behavior:
put(Appendable) or put(OutputStream) should result with JSON content in targeted Appendable or OutputStream instance.

Reproducible against current "master" using following test:

package osgi.enroute.dtos.bndlib.provider;
....
public class TestEncImpl extends TestCase {

	private static final String EXPECTED_ENCODED_CONTENT = "{\"id\":999,\"symbolicName\":\"com.example.test\"}";
	private static final BundleDTO bundleDTO = new BundleDTO();
	static {
		bundleDTO.id = 999;
		bundleDTO.symbolicName = "com.example.test";
	}

	private DTOs.Enc cut;

	public void setUp() throws Exception {
		cut = new DTOsProvider().encoder(bundleDTO);
	}

	public void testAppendable() throws Exception {
		try (Writer writer = new StringWriter()) {
			cut.put(writer);
			assertEquals(EXPECTED_ENCODED_CONTENT, writer.toString());
		}
	}

	public void testOutputStream() throws Exception {
		try (OutputStream os = new ByteArrayOutputStream()) {
			cut.put(os);
			assertEquals(EXPECTED_ENCODED_CONTENT, os.toString());
		}
		try (OutputStream os = new ByteArrayOutputStream()) {
			cut.put(os, "UTF-8");
			assertEquals(EXPECTED_ENCODED_CONTENT, os.toString());
		}
	}
}

Is Replace enRoute DTO with new Felix implementation related?

@pkriens
Copy link
Member

pkriens commented Nov 21, 2016

What is the test output?

@mcurcija
Copy link
Contributor Author

Output for testAppendable:

junit.framework.ComparisonFailure: expected:<[{"id":999,"symbolicName":"com.example.test"}]> but was:<[]>
	at junit.framework.Assert.assertEquals(Assert.java:100)
	at junit.framework.Assert.assertEquals(Assert.java:107)
	at junit.framework.TestCase.assertEquals(TestCase.java:269)
	at osgi.enroute.dtos.bndlib.provider.TestEncImpl.testAppendable(TestEncImpl.java:31)

Implementation in osgi.enroute.dtos.bndlib.provider.DTOsProvider.EncImpl.put(Appendable)
tries to put given Appendable instance instead of source.

		@Override
		public void put(Appendable out) throws Exception {
			enc.put(out);
		}

The difference between both put methods with OutputStream as argument is clear:

		@Override
		public void put(OutputStream out) throws Exception {
			codec.enc().charset("UTF-8").to(out).put(source);
		}

		@Override
		public void put(OutputStream out, String charset) throws Exception {
			enc.charset(charset).put(out);
		}

I can prepare pull request based on contributing document along with basic DTOsProvider.Enc/Inc test.

@bjhargrave
Copy link
Member

I can prepare pull request based on contributing document along with basic DTOsProvider.Enc/Inc test.

Please do!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants