Loading atlas-view/src/main/java/es/redmic/atlasview/mapper/category/CategoryESMapper.java 0 → 100644 +31 −0 Original line number Diff line number Diff line package es.redmic.atlasview.mapper.category; /*- * #%L * Atlas-query-endpoint * %% * Copyright (C) 2019 REDMIC Project / Server * %% * 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. * #L% */ import org.springframework.stereotype.Component; import es.redmic.atlaslib.dto.category.CategoryDTO; import es.redmic.atlasview.model.category.Category; import ma.glasnost.orika.CustomMapper; @Component public class CategoryESMapper extends CustomMapper<Category, CategoryDTO> { } atlas-view/src/test/java/es/redmic/test/atlasview/unit/mapper/CategoryMapperTest.java 0 → 100644 +107 −0 Original line number Diff line number Diff line package es.redmic.test.atlasview.unit.mapper; /*- * #%L * Atlas-query-endpoint * %% * Copyright (C) 2019 REDMIC Project / Server * %% * 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. * #L% */ import java.io.IOException; import org.json.JSONException; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.junit.MockitoJUnitRunner; import org.skyscreamer.jsonassert.JSONAssert; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import es.redmic.atlaslib.dto.category.CategoryDTO; import es.redmic.atlasview.config.MapperScanBean; import es.redmic.atlasview.mapper.category.CategoryESMapper; import es.redmic.atlasview.model.category.Category; import es.redmic.models.es.common.dto.JSONCollectionDTO; import es.redmic.models.es.data.common.model.DataSearchWrapper; import es.redmic.testutils.utils.JsonToBeanTestUtil; import es.redmic.viewlib.common.mapper.es2dto.DataCollectionESMapper; import es.redmic.viewlib.common.mapper.es2dto.DataItemESMapper; @RunWith(MockitoJUnitRunner.class) public class CategoryMapperTest { @InjectMocks CategoryESMapper mapper; @InjectMocks DataCollectionESMapper dataCollectionMapper; @InjectMocks DataItemESMapper dataItemMapper; protected MapperScanBean factory = new MapperScanBean().build(); // @formatter:off String modelPath = "/data/model/category/category.json", dtoToSavePath = "/data/dto/category/category.json", searchWrapperPath = "/data/model/category/searchWrapperCategoryESModel.json", searchDTOPath = "/data/dto/category/searchWrapperCategoryDTO.json"; // @formatter:on @Before public void setupTest() throws IOException { factory.addMapper(mapper); factory.addMapper(dataCollectionMapper); factory.addMapper(dataItemMapper); } @Test public void mapperDtoToModel() throws JsonParseException, JsonMappingException, IOException, JSONException { CategoryDTO dtoIn = (CategoryDTO) JsonToBeanTestUtil.getBean(dtoToSavePath, CategoryDTO.class); Category modelOut = factory.getMapperFacade().map(dtoIn, Category.class); String modelStringExpected = JsonToBeanTestUtil.getJsonString(modelPath); String modelString = JsonToBeanTestUtil.writeValueAsString(modelOut); JSONAssert.assertEquals(modelStringExpected, modelString, false); } @Test public void mapperSearchWrapperToDto() throws JsonParseException, JsonMappingException, IOException, JSONException { JavaType type = JsonToBeanTestUtil.getParametizedType(DataSearchWrapper.class, Category.class); DataSearchWrapper<?> searchWrapperModel = (DataSearchWrapper<?>) JsonToBeanTestUtil.getBean(searchWrapperPath, type); String expected = JsonToBeanTestUtil.getJsonString(searchDTOPath); JSONCollectionDTO searchDTO = factory.getMapperFacade().map(searchWrapperModel.getHits(), JSONCollectionDTO.class); String searchDTOString = JsonToBeanTestUtil.writeValueAsString(searchDTO); JSONAssert.assertEquals(expected, searchDTOString, false); } } atlas-view/src/test/resources/data/dto/category/category.json 0 → 100644 +4 −0 Original line number Diff line number Diff line { "id": "category-a31bd54e-836e-4942-b10b-8d7bdbd6f196", "name": "AIS" } No newline at end of file atlas-view/src/test/resources/data/dto/category/searchWrapperCategoryDTO.json 0 → 100644 +20 −0 Original line number Diff line number Diff line { "total": 1, "_meta": { "max_score": null }, "_aggs": { }, "data": [ { "_meta": { "score": 1.0, "version": 1, "highlight": null }, "id": "category-a31bd54e-836e-4942-b10b-8d7bdbd6f196", "name": "AIS" } ] } No newline at end of file atlas-view/src/test/resources/data/model/category/category.json 0 → 100644 +4 −0 Original line number Diff line number Diff line { "id": "category-a31bd54e-836e-4942-b10b-8d7bdbd6f196", "name": "AIS" } No newline at end of file Loading
atlas-view/src/main/java/es/redmic/atlasview/mapper/category/CategoryESMapper.java 0 → 100644 +31 −0 Original line number Diff line number Diff line package es.redmic.atlasview.mapper.category; /*- * #%L * Atlas-query-endpoint * %% * Copyright (C) 2019 REDMIC Project / Server * %% * 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. * #L% */ import org.springframework.stereotype.Component; import es.redmic.atlaslib.dto.category.CategoryDTO; import es.redmic.atlasview.model.category.Category; import ma.glasnost.orika.CustomMapper; @Component public class CategoryESMapper extends CustomMapper<Category, CategoryDTO> { }
atlas-view/src/test/java/es/redmic/test/atlasview/unit/mapper/CategoryMapperTest.java 0 → 100644 +107 −0 Original line number Diff line number Diff line package es.redmic.test.atlasview.unit.mapper; /*- * #%L * Atlas-query-endpoint * %% * Copyright (C) 2019 REDMIC Project / Server * %% * 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. * #L% */ import java.io.IOException; import org.json.JSONException; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.junit.MockitoJUnitRunner; import org.skyscreamer.jsonassert.JSONAssert; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import es.redmic.atlaslib.dto.category.CategoryDTO; import es.redmic.atlasview.config.MapperScanBean; import es.redmic.atlasview.mapper.category.CategoryESMapper; import es.redmic.atlasview.model.category.Category; import es.redmic.models.es.common.dto.JSONCollectionDTO; import es.redmic.models.es.data.common.model.DataSearchWrapper; import es.redmic.testutils.utils.JsonToBeanTestUtil; import es.redmic.viewlib.common.mapper.es2dto.DataCollectionESMapper; import es.redmic.viewlib.common.mapper.es2dto.DataItemESMapper; @RunWith(MockitoJUnitRunner.class) public class CategoryMapperTest { @InjectMocks CategoryESMapper mapper; @InjectMocks DataCollectionESMapper dataCollectionMapper; @InjectMocks DataItemESMapper dataItemMapper; protected MapperScanBean factory = new MapperScanBean().build(); // @formatter:off String modelPath = "/data/model/category/category.json", dtoToSavePath = "/data/dto/category/category.json", searchWrapperPath = "/data/model/category/searchWrapperCategoryESModel.json", searchDTOPath = "/data/dto/category/searchWrapperCategoryDTO.json"; // @formatter:on @Before public void setupTest() throws IOException { factory.addMapper(mapper); factory.addMapper(dataCollectionMapper); factory.addMapper(dataItemMapper); } @Test public void mapperDtoToModel() throws JsonParseException, JsonMappingException, IOException, JSONException { CategoryDTO dtoIn = (CategoryDTO) JsonToBeanTestUtil.getBean(dtoToSavePath, CategoryDTO.class); Category modelOut = factory.getMapperFacade().map(dtoIn, Category.class); String modelStringExpected = JsonToBeanTestUtil.getJsonString(modelPath); String modelString = JsonToBeanTestUtil.writeValueAsString(modelOut); JSONAssert.assertEquals(modelStringExpected, modelString, false); } @Test public void mapperSearchWrapperToDto() throws JsonParseException, JsonMappingException, IOException, JSONException { JavaType type = JsonToBeanTestUtil.getParametizedType(DataSearchWrapper.class, Category.class); DataSearchWrapper<?> searchWrapperModel = (DataSearchWrapper<?>) JsonToBeanTestUtil.getBean(searchWrapperPath, type); String expected = JsonToBeanTestUtil.getJsonString(searchDTOPath); JSONCollectionDTO searchDTO = factory.getMapperFacade().map(searchWrapperModel.getHits(), JSONCollectionDTO.class); String searchDTOString = JsonToBeanTestUtil.writeValueAsString(searchDTO); JSONAssert.assertEquals(expected, searchDTOString, false); } }
atlas-view/src/test/resources/data/dto/category/category.json 0 → 100644 +4 −0 Original line number Diff line number Diff line { "id": "category-a31bd54e-836e-4942-b10b-8d7bdbd6f196", "name": "AIS" } No newline at end of file
atlas-view/src/test/resources/data/dto/category/searchWrapperCategoryDTO.json 0 → 100644 +20 −0 Original line number Diff line number Diff line { "total": 1, "_meta": { "max_score": null }, "_aggs": { }, "data": [ { "_meta": { "score": 1.0, "version": 1, "highlight": null }, "id": "category-a31bd54e-836e-4942-b10b-8d7bdbd6f196", "name": "AIS" } ] } No newline at end of file
atlas-view/src/test/resources/data/model/category/category.json 0 → 100644 +4 −0 Original line number Diff line number Diff line { "id": "category-a31bd54e-836e-4942-b10b-8d7bdbd6f196", "name": "AIS" } No newline at end of file