From 2ebf26986c25d5fb9a722e238837d690f015d4d2 Mon Sep 17 00:00:00 2001 From: Sandeep Mantha Date: Wed, 4 Mar 2020 13:51:19 -0500 Subject: [PATCH 1/2] mongo auditview test case --- .../test/scenarios/s9/core/SampeS9core.java | 52 ++++++++++++ .../s9/view/VR_SampleMongoAudit.java | 58 +++++++++++++ .../scenarios/s9/view/VR_SampleS9view.java | 82 +++++++++++++++++++ ...ateAtomicPersistenceEventListenerTest.java | 51 ++++++++++++ 4 files changed, 243 insertions(+) create mode 100644 nimbus-test/src/main/java/com/antheminc/oss/nimbus/test/scenarios/s9/core/SampeS9core.java create mode 100644 nimbus-test/src/main/java/com/antheminc/oss/nimbus/test/scenarios/s9/view/VR_SampleMongoAudit.java create mode 100644 nimbus-test/src/main/java/com/antheminc/oss/nimbus/test/scenarios/s9/view/VR_SampleS9view.java diff --git a/nimbus-test/src/main/java/com/antheminc/oss/nimbus/test/scenarios/s9/core/SampeS9core.java b/nimbus-test/src/main/java/com/antheminc/oss/nimbus/test/scenarios/s9/core/SampeS9core.java new file mode 100644 index 000000000..a631012b1 --- /dev/null +++ b/nimbus-test/src/main/java/com/antheminc/oss/nimbus/test/scenarios/s9/core/SampeS9core.java @@ -0,0 +1,52 @@ +/** + * Copyright 2016-2019 the original author or authors. + * + * 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 com.antheminc.oss.nimbus.test.scenarios.s9.core; + +import com.antheminc.oss.nimbus.domain.defn.Domain; +import com.antheminc.oss.nimbus.domain.defn.Repo; +import com.antheminc.oss.nimbus.domain.defn.Domain.ListenerType; +import com.antheminc.oss.nimbus.domain.defn.Repo.Cache; +import com.antheminc.oss.nimbus.domain.defn.Repo.Database; +import com.antheminc.oss.nimbus.entity.AbstractEntity.IdLong; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + * @author Sandeep Mantha + * + */ +@Domain(value="sample_s9_core", includeListeners = { ListenerType.persistence }) +@Repo(alias = "sample_s9_core", value = Database.rep_mongodb, cache = Cache.rep_device) +@Getter @Setter @ToString +public class SampeS9core extends IdLong { + + private static final long serialVersionUID = 1L; + + private String attr1; + + private String attr2; + + private String attr3; + + private String attr4; + + + +} + + diff --git a/nimbus-test/src/main/java/com/antheminc/oss/nimbus/test/scenarios/s9/view/VR_SampleMongoAudit.java b/nimbus-test/src/main/java/com/antheminc/oss/nimbus/test/scenarios/s9/view/VR_SampleMongoAudit.java new file mode 100644 index 000000000..de20b2b20 --- /dev/null +++ b/nimbus-test/src/main/java/com/antheminc/oss/nimbus/test/scenarios/s9/view/VR_SampleMongoAudit.java @@ -0,0 +1,58 @@ +/** + * Copyright 2016-2019 the original author or authors. + * + * 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 com.antheminc.oss.nimbus.test.scenarios.s9.view; + +import com.antheminc.oss.nimbus.domain.defn.Domain; +import com.antheminc.oss.nimbus.domain.defn.Domain.ListenerType; +import com.antheminc.oss.nimbus.domain.defn.MapsTo; +import com.antheminc.oss.nimbus.domain.defn.MapsTo.Path; +import com.antheminc.oss.nimbus.domain.defn.Repo; +import com.antheminc.oss.nimbus.domain.defn.Repo.Cache; +import com.antheminc.oss.nimbus.domain.defn.extension.AuditView; +import com.antheminc.oss.nimbus.entity.AbstractEntity.IdLong; +import com.antheminc.oss.nimbus.test.scenarios.s9.core.SampeS9core; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + * @author Sandeep Mantha + * + */ +@Domain(value = "sample_s9_auditview", includeListeners = { ListenerType.none }) +@MapsTo.Type(SampeS9core.class) +@AuditView +@Repo(value=Repo.Database.rep_mongodb, cache=Cache.rep_none) +@Getter @Setter @ToString +public class VR_SampleMongoAudit extends IdLong{ + + private static final long serialVersionUID = 1L; + + @Path("/id") + private Long entityId; + + @Path + private String attr1; + + @Path + private String attr2; + + + +} + + diff --git a/nimbus-test/src/main/java/com/antheminc/oss/nimbus/test/scenarios/s9/view/VR_SampleS9view.java b/nimbus-test/src/main/java/com/antheminc/oss/nimbus/test/scenarios/s9/view/VR_SampleS9view.java new file mode 100644 index 000000000..9ad16b4db --- /dev/null +++ b/nimbus-test/src/main/java/com/antheminc/oss/nimbus/test/scenarios/s9/view/VR_SampleS9view.java @@ -0,0 +1,82 @@ +/** + * Copyright 2016-2019 the original author or authors. + * + * 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 com.antheminc.oss.nimbus.test.scenarios.s9.view; + +import com.antheminc.oss.nimbus.domain.defn.Domain; +import com.antheminc.oss.nimbus.domain.defn.Domain.ListenerType; +import com.antheminc.oss.nimbus.domain.defn.MapsTo; +import com.antheminc.oss.nimbus.domain.defn.MapsTo.Path; +import com.antheminc.oss.nimbus.domain.defn.Model; +import com.antheminc.oss.nimbus.domain.defn.Repo; +import com.antheminc.oss.nimbus.domain.defn.Repo.Cache; +import com.antheminc.oss.nimbus.domain.defn.Repo.Database; +import com.antheminc.oss.nimbus.domain.defn.ViewConfig.Form; +import com.antheminc.oss.nimbus.domain.defn.ViewConfig.Page; +import com.antheminc.oss.nimbus.domain.defn.ViewConfig.Section; +import com.antheminc.oss.nimbus.domain.defn.ViewConfig.Tile; +import com.antheminc.oss.nimbus.test.scenarios.s9.core.SampeS9core; + +import lombok.Getter; +import lombok.Setter; + +/** + * @author Sandeep Mantha + * + */ +@Domain(value = "sample_s9_view", includeListeners = { ListenerType.websocket }) +@MapsTo.Type(SampeS9core.class) +@Repo(value=Database.rep_none, cache=Cache.rep_device) +@Getter +@Setter +public class VR_SampleS9view { + + @Page + private VPMain vp; + + @Model @Getter @Setter + public static class VPMain { + + @Tile + private VTMain vt; + } + + @Model @Getter @Setter + public static class VTMain { + + @Section + private VSMain vs; + } + + @Model @Getter @Setter + public static class VSMain { + + @Form + private VFMain vf; + } + + @MapsTo.Type(SampeS9core.class) + @Model @Getter @Setter + public static class VFMain { + + @Path + private String attr1; + + @Path + private String attr2; + + } + +} \ No newline at end of file diff --git a/nimbus-test/src/test/java/com/antheminc/oss/nimbus/domain/model/state/repo/db/ParamStateAtomicPersistenceEventListenerTest.java b/nimbus-test/src/test/java/com/antheminc/oss/nimbus/domain/model/state/repo/db/ParamStateAtomicPersistenceEventListenerTest.java index 04e364ccd..852ac73c0 100644 --- a/nimbus-test/src/test/java/com/antheminc/oss/nimbus/domain/model/state/repo/db/ParamStateAtomicPersistenceEventListenerTest.java +++ b/nimbus-test/src/test/java/com/antheminc/oss/nimbus/domain/model/state/repo/db/ParamStateAtomicPersistenceEventListenerTest.java @@ -15,19 +15,34 @@ */ package com.antheminc.oss.nimbus.domain.model.state.repo.db; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.util.Arrays; +import java.util.List; + import org.junit.Assert; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.mock.web.MockHttpServletRequest; +import com.antheminc.oss.nimbus.domain.cmd.Action; import com.antheminc.oss.nimbus.domain.cmd.Command; import com.antheminc.oss.nimbus.domain.cmd.CommandMessage; import com.antheminc.oss.nimbus.domain.cmd.exec.CommandExecutorGateway; +import com.antheminc.oss.nimbus.domain.model.state.EntityState.Param; import com.antheminc.oss.nimbus.support.CommandUtils; import com.antheminc.oss.nimbus.test.domain.support.AbstractFrameworkIntegrationTests; +import com.antheminc.oss.nimbus.test.domain.support.utils.ExtractResponseOutputUtils; +import com.antheminc.oss.nimbus.test.domain.support.utils.MockHttpRequestBuilder; +import com.antheminc.oss.nimbus.test.domain.support.utils.ParamUtils; import com.antheminc.oss.nimbus.test.scenarios.repo.core.SampleRepoDifferentAlias; +import com.antheminc.oss.nimbus.test.scenarios.s0.core.SampleCoreEntity; +import com.antheminc.oss.nimbus.test.scenarios.s9.view.VR_SampleMongoAudit; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -38,6 +53,8 @@ @EnableAutoConfiguration public class ParamStateAtomicPersistenceEventListenerTest extends AbstractFrameworkIntegrationTests { + protected static final String VIEW_PARAM_ROOT = PLATFORM_ROOT + "/sample_s9_view"; + @Autowired @Qualifier("default.processGateway") private CommandExecutorGateway commandGateway; @@ -63,4 +80,38 @@ public void testDomainRepoAliasMismatchPersistence() throws JsonProcessingExcept // @Repo.alias, not @Domain.value Assert.assertEquals(expected, mongo.findById(1L, SampleRepoDifferentAlias.class, expectedCollectionName)); } + + @Test + public void testAuditView() { + MockHttpServletRequest newReq = MockHttpRequestBuilder.withUri(VIEW_PARAM_ROOT).addAction(Action._new).getMock(); + Object newResp = controller.handleGet(newReq, null); + assertNotNull(newResp); + Long domainRoot_refId = ExtractResponseOutputUtils.extractDomainRootRefId(newResp); + + MockHttpServletRequest request = MockHttpRequestBuilder.withUri(VIEW_PARAM_ROOT).addRefId(domainRoot_refId) + .addNested("/vp/vt/vs/vf/attr1").addAction(Action._update).getMock(); + Object response1 = controller.handlePut(request, null, converter.toJson("test1")); + Param> viewParam = ParamUtils.extractResponseByParamPath(response1, "/vp/vt/vs/vf/attr1"); + assertEquals("test1", viewParam.getState()); + + List auditList = mongo.findAll(VR_SampleMongoAudit.class, "sample_s9_auditview"); + assertEquals(auditList.size(), 1); + assertEquals(auditList.get(0).getAttr1(),"test1"); + assertNull(auditList.get(0).getAttr2()); + + + MockHttpServletRequest request2 = MockHttpRequestBuilder.withUri(VIEW_PARAM_ROOT).addRefId(domainRoot_refId) + .addNested("/vp/vt/vs/vf/attr2").addAction(Action._update).getMock(); + Object response2 = controller.handlePut(request2, null, converter.toJson("test2")); + Param> viewParam2 = ParamUtils.extractResponseByParamPath(response2, "/vp/vt/vs/vf/attr2"); + assertEquals("test2", viewParam2.getState()); + + List auditLst = mongo.findAll(VR_SampleMongoAudit.class, "sample_s9_auditview"); + assertEquals(auditLst.size(), 2); + assertEquals(auditLst.get(0).getAttr1(),"test1"); + assertNull(auditLst.get(0).getAttr2()); + assertEquals(auditLst.get(1).getAttr1(),"test1"); + assertEquals(auditLst.get(1).getAttr2(),"test2"); + + } } From 1011703b65d2a2f775d463c17510722b1057592f Mon Sep 17 00:00:00 2001 From: Sandeep Mantha Date: Wed, 4 Mar 2020 14:19:07 -0500 Subject: [PATCH 2/2] @auditview for core save --- ...ateAtomicPersistenceEventListenerTest.java | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/nimbus-test/src/test/java/com/antheminc/oss/nimbus/domain/model/state/repo/db/ParamStateAtomicPersistenceEventListenerTest.java b/nimbus-test/src/test/java/com/antheminc/oss/nimbus/domain/model/state/repo/db/ParamStateAtomicPersistenceEventListenerTest.java index 852ac73c0..de868b17f 100644 --- a/nimbus-test/src/test/java/com/antheminc/oss/nimbus/domain/model/state/repo/db/ParamStateAtomicPersistenceEventListenerTest.java +++ b/nimbus-test/src/test/java/com/antheminc/oss/nimbus/domain/model/state/repo/db/ParamStateAtomicPersistenceEventListenerTest.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertNull; import java.util.Arrays; +import java.util.Date; import java.util.List; import org.junit.Assert; @@ -42,6 +43,7 @@ import com.antheminc.oss.nimbus.test.domain.support.utils.ParamUtils; import com.antheminc.oss.nimbus.test.scenarios.repo.core.SampleRepoDifferentAlias; import com.antheminc.oss.nimbus.test.scenarios.s0.core.SampleCoreEntity; +import com.antheminc.oss.nimbus.test.scenarios.s9.core.SampeS9core; import com.antheminc.oss.nimbus.test.scenarios.s9.view.VR_SampleMongoAudit; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -54,6 +56,9 @@ public class ParamStateAtomicPersistenceEventListenerTest extends AbstractFrameworkIntegrationTests { protected static final String VIEW_PARAM_ROOT = PLATFORM_ROOT + "/sample_s9_view"; + + protected static final String CORE_PARAM_ROOT = PLATFORM_ROOT + "/sample_s9_core"; + @Autowired @Qualifier("default.processGateway") @@ -82,7 +87,7 @@ public void testDomainRepoAliasMismatchPersistence() throws JsonProcessingExcept } @Test - public void testAuditView() { + public void testView_update() { MockHttpServletRequest newReq = MockHttpRequestBuilder.withUri(VIEW_PARAM_ROOT).addAction(Action._new).getMock(); Object newResp = controller.handleGet(newReq, null); assertNotNull(newResp); @@ -114,4 +119,38 @@ public void testAuditView() { assertEquals(auditLst.get(1).getAttr2(),"test2"); } + + @Test + public void testCore_save() { + MockHttpServletRequest newReq = MockHttpRequestBuilder.withUri(VIEW_PARAM_ROOT).addAction(Action._new).getMock(); + Object newResp = controller.handleGet(newReq, null); + assertNotNull(newResp); + Long domainRoot_refId = ExtractResponseOutputUtils.extractDomainRootRefId(newResp); + + Object resp_save = controller.handlePost(MockHttpRequestBuilder.withUri(CORE_PARAM_ROOT).addRefId(domainRoot_refId) + .addNested("/attr1").addAction(Action._update).getMock(), converter.toJson("test1")); + assertNotNull(resp_save); + + List auditList = mongo.findAll(VR_SampleMongoAudit.class, "sample_s9_auditview"); + assertEquals(auditList.size(), 1); + assertEquals(auditList.get(0).getAttr1(),"test1"); + assertNull(auditList.get(0).getAttr2()); + + SampeS9core core = mongo.findById(domainRoot_refId, SampeS9core.class, "sample_s9_core"); + assertEquals(core.getAttr1(),"test1"); + + Object resp_save1 = controller.handleGet( + MockHttpRequestBuilder.withUri(CORE_PARAM_ROOT).addRefId(domainRoot_refId).addAction(Action._save).getMock(), null); + assertNotNull(resp_save1); + + SampeS9core core1 = mongo.findById(domainRoot_refId, SampeS9core.class, "sample_s9_core"); + assertEquals(core1.getAttr1(),"test1"); + + List auditLst = mongo.findAll(VR_SampleMongoAudit.class, "sample_s9_auditview"); + assertEquals(auditLst.size(), 2); + assertEquals(auditLst.get(0).getAttr1(),"test1"); + assertNull(auditLst.get(1).getAttr2()); + + } + }