diff --git a/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/controllers/ConfigurationControllerPermitAllTest.java b/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/controllers/ConfigurationControllerPermitAllTest.java index d84aebc598..ebcdbf45ef 100644 --- a/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/controllers/ConfigurationControllerPermitAllTest.java +++ b/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/controllers/ConfigurationControllerPermitAllTest.java @@ -20,8 +20,10 @@ package org.phoebus.service.saveandrestore.web.controllers; import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mockito; import org.phoebus.applications.saveandrestore.model.Configuration; import org.phoebus.applications.saveandrestore.model.ConfigurationData; import org.phoebus.applications.saveandrestore.model.Node; @@ -70,11 +72,14 @@ public class ConfigurationControllerPermitAllTest { @Autowired private String demoUser; + @AfterEach + public void resetMocks(){ + reset(nodeDAO); + } + @Test public void testCreateConfiguration() throws Exception { - reset(nodeDAO); - Configuration configuration = new Configuration(); configuration.setConfigurationNode(Node.builder().build()); ConfigurationData configurationData = new ConfigurationData(); @@ -84,6 +89,9 @@ public void testCreateConfiguration() throws Exception { .header(HttpHeaders.AUTHORIZATION, userAuthorization) .contentType(JSON).content(objectMapper.writeValueAsString(configuration)); + when(nodeDAO.createConfiguration(Mockito.anyString(), Mockito.any(Configuration.class))) + .thenReturn(configuration); + mockMvc.perform(request).andExpect(status().isOk()); request = put("/config?parentNodeId=a") @@ -107,6 +115,8 @@ public void testUpdateConfiguration() throws Exception { configuration.setConfigurationNode(configurationNode); when(nodeDAO.getNode("uniqueId")).thenReturn(configurationNode); + when(nodeDAO.updateConfiguration(Mockito.any(Configuration.class))) + .thenReturn(configuration); MockHttpServletRequestBuilder request = post("/config") .header(HttpHeaders.AUTHORIZATION, userAuthorization) diff --git a/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/controllers/ConfigurationControllerTest.java b/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/controllers/ConfigurationControllerTest.java index bc114aa464..ecfc9de044 100644 --- a/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/controllers/ConfigurationControllerTest.java +++ b/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/controllers/ConfigurationControllerTest.java @@ -49,6 +49,7 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; +import java.util.Collections; import java.util.List; import static org.mockito.Mockito.reset; @@ -104,6 +105,9 @@ public void testCreateConfiguration1() throws Exception { configurationData.setPvList(List.of(ConfigPv.builder().pvName("foo").readbackPvName("bar").build())); configuration.setConfigurationData(configurationData); + + when(nodeDAO.createConfiguration(Mockito.anyString(), Mockito.any(Configuration.class))) + .thenReturn(configuration); MockHttpServletRequestBuilder request = put("/config?parentNodeId=a") .header(HttpHeaders.AUTHORIZATION, adminAuthorization) .contentType(JSON).content(objectMapper.writeValueAsString(configuration)); @@ -118,6 +122,12 @@ public void testCreateConfiguration2() throws Exception { Configuration configuration = new Configuration(); configuration.setConfigurationNode(Node.builder().build()); + ConfigurationData configurationData = new ConfigurationData(); + configurationData.setPvList(Collections.emptyList()); + configuration.setConfigurationData(configurationData); + + when(nodeDAO.createConfiguration(Mockito.anyString(), Mockito.any(Configuration.class))) + .thenReturn(configuration); MockHttpServletRequestBuilder request = put("/config?parentNodeId=a") .header(HttpHeaders.AUTHORIZATION, userAuthorization) @@ -167,6 +177,8 @@ public void testUpdateConfiguration1() throws Exception { configuration.setConfigurationNode(configurationNode); when(nodeDAO.getNode("uniqueId")).thenReturn(configurationNode); + when(nodeDAO.updateConfiguration(Mockito.any(Configuration.class))) + .thenReturn(configuration); MockHttpServletRequestBuilder request = post("/config") .header(HttpHeaders.AUTHORIZATION, userAuthorization) @@ -186,6 +198,8 @@ public void tesUpdateConfiguration2() throws Exception { configuration.setConfigurationNode(configurationNode); when(nodeDAO.getNode("uniqueId")).thenReturn(configurationNode); + when(nodeDAO.updateConfiguration(Mockito.any(Configuration.class))) + .thenReturn(configuration); MockHttpServletRequestBuilder request = post("/config") .header(HttpHeaders.AUTHORIZATION, userAuthorization) @@ -204,6 +218,8 @@ public void testUpdateConfiguration3() throws Exception { configuration.setConfigurationNode(configurationNode); when(nodeDAO.getNode("uniqueId")).thenReturn(configurationNode); + when(nodeDAO.updateConfiguration(Mockito.any(Configuration.class))) + .thenReturn(configuration); MockHttpServletRequestBuilder request = post("/config") .header(HttpHeaders.AUTHORIZATION, adminAuthorization) diff --git a/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/controllers/SnapshotControllerTest.java b/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/controllers/SnapshotControllerTest.java index 43dc9378e9..8aaddec51c 100644 --- a/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/controllers/SnapshotControllerTest.java +++ b/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/controllers/SnapshotControllerTest.java @@ -184,6 +184,9 @@ public void testCreateSnapshot3() throws Exception{ String snapshotString = objectMapper.writeValueAsString(snapshot); + when(nodeDAO.createSnapshot(Mockito.anyString(), Mockito.any(Snapshot.class))) + .thenReturn(snapshot); + MockHttpServletRequestBuilder request = put("/snapshot?parentNodeId=a") .header(HttpHeaders.AUTHORIZATION, adminAuthorization) .contentType(JSON) @@ -263,6 +266,9 @@ public void testUpdateSnapshot4() throws Exception{ String snapshotString = objectMapper.writeValueAsString(snapshot); + when(nodeDAO.updateSnapshot(Mockito.any(Snapshot.class))) + .thenReturn(snapshot); + MockHttpServletRequestBuilder request = post("/snapshot") .header(HttpHeaders.AUTHORIZATION, adminAuthorization) .contentType(JSON)