@@ -0,0 +1,3037 @@
+package uk.gov.register.views;%0A%0Aimport com.fasterxml.jackson.databind.JsonNode;%0Aimport com.fasterxml.jackson.databind.ObjectMapper;%0Aimport com.fasterxml.jackson.databind.node.ArrayNode;%0Aimport com.google.common.collect.ImmutableList;%0Aimport com.google.common.collect.ImmutableMap;%0Aimport io.dropwizard.jackson.Jackson;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport uk.gov.register.core.Cardinality;%0Aimport uk.gov.register.core.Field;%0Aimport uk.gov.register.core.HashingAlgorithm;%0Aimport uk.gov.register.core.Item;%0Aimport uk.gov.register.core.RegisterId;%0Aimport uk.gov.register.util.HashValue;%0Aimport uk.gov.register.views.representations.CsvWriter;%0A%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.io.IOException;%0Aimport java.nio.charset.StandardCharsets;%0Aimport java.util.Map;%0A%0Aimport static org.hamcrest.CoreMatchers.equalTo;%0Aimport static org.junit.Assert.assertThat;%0Aimport static org.junit.Assert.assertTrue;%0A%0Apublic class ItemListViewTest %7B%0A%0A    private final ObjectMapper objectMapper = Jackson.newObjectMapper();%0A    private JsonNode itemNode1;%0A    private JsonNode itemNode2;%0A    private ItemListView view;%0A%0A    @Before%0A    public void setup() throws IOException %7B%0A        itemNode1 = objectMapper.readTree(%22%7B%5C%22address%5C%22:%5C%22123%5C%22,%5C%22street%5C%22:%5C%22foo%5C%22%7D%22);%0A        Item item1 = new Item(new HashValue(HashingAlgorithm.SHA256, %22ab%22), itemNode1);%0A%0A        itemNode2 = objectMapper.readTree(%22%7B%5C%22address%5C%22:%5C%22456%5C%22,%5C%22street%5C%22:%5C%22bar%5C%22%7D%22);%0A        Item item2 = new Item(new HashValue(HashingAlgorithm.SHA256, %22cd%22), itemNode2);%0A%0A        Map%3CString, Field%3E fieldsByName = ImmutableMap.of(%0A                %22street%22, new Field(%22street%22, %22string%22, new RegisterId(%22foo%22), Cardinality.ONE, %22bla%22),%0A                %22address%22, new Field(%22address%22, %22string%22, new RegisterId(%22foo%22), Cardinality.ONE, %22bla%22)%0A        );%0A%0A        this.view = new ItemListView(ImmutableList.of(item1, item2), fieldsByName);%0A    %7D%0A%0A    @Test%0A    public void jsonRepresentation() throws IOException %7B%0A        String result = objectMapper.writeValueAsString(view);%0A%0A        JsonNode jsonNode = objectMapper.readTree(result);%0A%0A        assertTrue(jsonNode.has(%22sha-256:ab%22));%0A        assertTrue(jsonNode.has(%22sha-256:cd%22));%0A%0A        assertThat(jsonNode.get(%22sha-256:ab%22), equalTo(itemNode1));%0A        assertThat(jsonNode.get(%22sha-256:cd%22), equalTo(itemNode2));%0A    %7D%0A%0A    @Test%0A    public void csvRepresentation() throws IOException %7B%0A        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();%0A        CsvWriter csvWriter = new CsvWriter();%0A        csvWriter.writeTo(view,%0A                ArrayNode.class,%0A                null,%0A                null,%0A                null,%0A                null,%0A                outputStream);%0A        byte%5B%5D bytes = outputStream.toByteArray();%0A        String result = new String(bytes, StandardCharsets.UTF_8);%0A%0A        assertThat(result, equalTo(%0A                %22blob-hash,street,address%5Cr%5Cn%22 +%0A                        %22sha-256:cd,bar,456%5Cr%5Cn%22 +%0A                        %22sha-256:ab,foo,123%5Cr%5Cn%22%0A%0A        ));%0A    %7D%0A%7D%0A

Test ItemListView