Skip to content
Snippets Groups Projects
Commit a98fc474 authored by Sviatoslav Nekhaienko's avatar Sviatoslav Nekhaienko
Browse files

fix unit tests

parent 203605fe
No related branches found
Tags v0.7.0
1 merge request!60Indexer to read from Schema Service as well as Storage Schema
// Copyright 2017-2019, Schlumberger
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.indexer.schema.converter;
import lombok.AccessLevel;
......
// Copyright 2017-2019, Schlumberger
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.indexer.schema.converter;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import javax.inject.Inject;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
......@@ -19,15 +31,13 @@ import java.util.Map;
import static org.junit.Assert.assertEquals;
@RunWith(SpringRunner.class)
@SpringBootTest
public class SchemaToStorageFormatImplTest {
@Inject
private ObjectMapper objectMapper;
private ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
@Inject
SchemaToStorageFormatImpl schemaToStorageFormatImpl;
private SchemaToStorageFormatImpl schemaToStorageFormatImpl = new SchemaToStorageFormatImpl(objectMapper);
@Test
public void firstSchemaPassed() throws IOException, URISyntaxException {
......@@ -63,23 +73,23 @@ public class SchemaToStorageFormatImplTest {
}
private void compareSchemas(Map<String, Object> expected, Map<String, Object> converted) {
assertEquals(converted.size(), expected.size());
assertEquals(converted.get("kind"), expected.get("kind"));
assertEquals(expected.size(), converted.size());
assertEquals(expected.get("kind"), converted.get("kind"));
ArrayList<Map<String, String>> conv = (ArrayList<Map<String, String>>) converted.get("schema");
ArrayList<Map<String, String>> exp = (ArrayList<Map<String, String>>) expected.get("schema");
checkSchemaIteamsAreEqual(conv, exp);
checkSchemaIteamsAreEqual(exp, conv);
}
private void checkSchemaIteamsAreEqual(ArrayList<Map<String, String>> conv, List<Map<String, String>> exp) {
assertEquals(conv.size(), exp.size());
private void checkSchemaIteamsAreEqual(ArrayList<Map<String, String>> exp, List<Map<String, String>> conv) {
assertEquals(exp.size(), conv.size());
conv.forEach((c) -> checkItemIn(c, exp));
}
private void checkItemIn(Map<String, String> item, List<Map<String, String>> exp) {
String itemPath = item.get("path");
assertEquals(exp.stream().filter(e->itemPath.equals(e.get("path"))).count(), 1L);
assertEquals(itemPath + " is missed(or too many) see count", exp.stream().filter(e->itemPath.equals(e.get("path"))).count(), 1L);
Map<String, String> found = exp.stream().filter(e->item.get("path").equals(e.get("path"))).findAny().get();
assertEquals(found.get("kind"), item.get("kind"), "In " + itemPath);
assertEquals("In " + itemPath, found.get("kind"), item.get("kind"));
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment