Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;



}


Original file line number Diff line number Diff line change
@@ -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;



}


Original file line number Diff line number Diff line change
@@ -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;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,36 @@
*/
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.Date;
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.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;

Expand All @@ -38,6 +55,11 @@
@EnableAutoConfiguration
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")
private CommandExecutorGateway commandGateway;
Expand All @@ -63,4 +85,72 @@ public void testDomainRepoAliasMismatchPersistence() throws JsonProcessingExcept
// @Repo.alias, not @Domain.value
Assert.assertEquals(expected, mongo.findById(1L, SampleRepoDifferentAlias.class, expectedCollectionName));
}

@Test
public void testView_update() {
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<List<String>> viewParam = ParamUtils.extractResponseByParamPath(response1, "/vp/vt/vs/vf/attr1");
assertEquals("test1", viewParam.getState());

List<VR_SampleMongoAudit> 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<List<String>> viewParam2 = ParamUtils.extractResponseByParamPath(response2, "/vp/vt/vs/vf/attr2");
assertEquals("test2", viewParam2.getState());

List<VR_SampleMongoAudit> 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");

}

@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<VR_SampleMongoAudit> 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<VR_SampleMongoAudit> auditLst = mongo.findAll(VR_SampleMongoAudit.class, "sample_s9_auditview");
assertEquals(auditLst.size(), 2);
assertEquals(auditLst.get(0).getAttr1(),"test1");
assertNull(auditLst.get(1).getAttr2());

}

}