From 063314bab3d9c67e3497e475d46c15783e1c0d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Wed, 25 Dec 2019 14:09:00 +0100 Subject: Add client api documentation --- .../mimuw/cloudatlas/client/ClientController.java | 25 +++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java index db9c09f..120d80d 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java @@ -13,16 +13,21 @@ import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import java.util.*; -/* -should enable reading attribute values stored by the agent -installing and -uninstalling queries, and -setting fallback contacts. - -Apart from providing forms for queries and fallback contacts, -and presenting the information fetched from the agent in a textual form (with automatic refreshment), -plotting the attributes with numeric values as real-time graphs. -*/ +/** + * APIs + * / + * /query - displays query submission form + * /installQuery - posts query installation data + * /uninstallQuery - posts query uninstallation data + * /contacts - GET - displays contacts submission form + * /contacts - POST - posts contacts installation data + * /attribs - GET - displays attribute submission form + * /attribs - POST - posts attribute submission data + * /values - GET - displays attributes values + * /values - POST - posts zone change data + * /attribNumValues - REST API to get numerical attribute values + * /attribAllValues - REST API to get all attribute values + */ @Controller public class ClientController { -- cgit v1.2.3 From b807c4ea723736f07bd25cec86908854679fda0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Wed, 25 Dec 2019 14:33:59 +0100 Subject: Add client GET tests --- build.gradle | 2 + .../pl/edu/mimuw/cloudatlas/client/ClientTest.java | 70 ++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 src/test/java/pl/edu/mimuw/cloudatlas/client/ClientTest.java diff --git a/build.gradle b/build.gradle index 82a430e..9ef400c 100644 --- a/build.gradle +++ b/build.gradle @@ -33,6 +33,8 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-thymeleaf:2.2.1.RELEASE' + implementation 'org.springframework.boot:spring-boot-starter-test:2.2.1.RELEASE' + // Use JUnit test framework testImplementation 'junit:junit:4.12' diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/client/ClientTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/client/ClientTest.java new file mode 100644 index 0000000..750e2cb --- /dev/null +++ b/src/test/java/pl/edu/mimuw/cloudatlas/client/ClientTest.java @@ -0,0 +1,70 @@ +package pl.edu.mimuw.cloudatlas.client; + +import org.hamcrest.CoreMatchers; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.test.context.junit4.SpringRunner; +import pl.edu.mimuw.cloudatlas.api.Api; + +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; + +import static org.junit.Assert.assertThat; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class ClientTest { + private static Process registryProcess; + private static Process agentProcess; + private static Process clientProcess; + + private static Registry registry; + private static Api api; + + @BeforeClass + public static void bindApi() throws Exception { + registryProcess = Runtime.getRuntime().exec("./scripts/registry"); + Thread.sleep(10000); + agentProcess = Runtime.getRuntime().exec("./gradlew runAgent -Dhostname=localhost"); + Thread.sleep(10000); + + registry = LocateRegistry.getRegistry("localhost"); + api = (Api) registry.lookup("Api"); + } + + @AfterClass + public static void killProcesses() throws Exception { + try { + registryProcess.destroy(); + agentProcess.destroy(); + } catch (Exception e) { + System.out.println("Caught exception: " + e); + } + } + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplate restTemplate; + + @Test + public void homeMessageCheck() throws Exception { + Thread.sleep(100); + String response = this.restTemplate.getForObject("http://localhost:" + port + "/", String.class); + assertThat(response, CoreMatchers.containsString("Welcome to CloudaAtlas client interface")); + } + + @Test + public void attributeValuesMessageCheck() throws Exception { + Thread.sleep(100); + String response = this.restTemplate.getForObject("http://localhost:" + port + "/values", String.class); + assertThat(response, CoreMatchers.containsString("Attribute values")); + } +} -- cgit v1.2.3 From cafcc4242fe6b6bc72a65b1012527fb1c0ebb3e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Wed, 25 Dec 2019 14:40:15 +0100 Subject: Add tests skeleton values --- .../pl/edu/mimuw/cloudatlas/client/ClientTest.java | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/client/ClientTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/client/ClientTest.java index 750e2cb..13b9fd7 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/client/ClientTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/client/ClientTest.java @@ -56,15 +56,33 @@ public class ClientTest { @Test public void homeMessageCheck() throws Exception { - Thread.sleep(100); String response = this.restTemplate.getForObject("http://localhost:" + port + "/", String.class); assertThat(response, CoreMatchers.containsString("Welcome to CloudaAtlas client interface")); } @Test public void attributeValuesMessageCheck() throws Exception { - Thread.sleep(100); String response = this.restTemplate.getForObject("http://localhost:" + port + "/values", String.class); assertThat(response, CoreMatchers.containsString("Attribute values")); } + + @Test + public void queryInstallationCheck() throws Exception { + // TODO + } + + @Test + public void queryUninstallationCheck() throws Exception { + // TODO + } + + @Test + public void numericalRESTApiCheck() throws Exception { + // TODO + } + + @Test + public void allValuesRESTApiCheck() throws Exception { + // TODO + } } -- cgit v1.2.3 From f51288ab6ac7b968be99a19784cd9c8de068f18c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Wed, 25 Dec 2019 16:04:58 +0100 Subject: Extend client tests --- .../pl/edu/mimuw/cloudatlas/client/ClientTest.java | 66 ++++++++++++++++++++-- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/client/ClientTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/client/ClientTest.java index 13b9fd7..431122b 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/client/ClientTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/client/ClientTest.java @@ -6,18 +6,24 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.MediaType; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; import pl.edu.mimuw.cloudatlas.api.Api; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import static org.junit.Assert.assertThat; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; @RunWith(SpringRunner.class) +@AutoConfigureMockMvc @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class ClientTest { private static Process registryProcess; @@ -51,6 +57,9 @@ public class ClientTest { @LocalServerPort private int port; + @Autowired + private MockMvc mvc; + @Autowired private TestRestTemplate restTemplate; @@ -68,21 +77,70 @@ public class ClientTest { @Test public void queryInstallationCheck() throws Exception { - // TODO + this.mvc.perform(post("/installQuery") + .param("name", "&sampleQuery") + .param("value", "SELECT 1 AS one")) + .andExpect(status().isOk()).andExpect(content() + .contentType("text/html;charset=UTF-8")) + .andExpect(content().string(CoreMatchers.containsString("Query installed successfully"))); } @Test public void queryUninstallationCheck() throws Exception { - // TODO + this.mvc.perform(post("/installQuery") + .param("name", "&sampleQuery") + .param("value", "SELECT 1 AS one")) + .andExpect(status().isOk()).andExpect(content() + .contentType("text/html;charset=UTF-8")) + .andExpect(content().string(CoreMatchers.containsString("Query installed successfully"))); + + this.mvc.perform(post("/uninstallQuery") + .param("name", "&sampleQuery")) + .andExpect(status().isOk()).andExpect(content() + .contentType("text/html;charset=UTF-8")) + .andExpect(content().string(CoreMatchers.containsString("Query uninstalled successfully"))); + } + + @Test + public void attributeInstallationCheck() throws Exception { + this.mvc.perform(post("/attribs") + .param("zoneName", "/") + .param("attributeName", "a") + .param("attributeType", "Int") + .param("valueString", "1")) + .andExpect(status().isOk()).andExpect(content() + .contentType("text/html;charset=UTF-8")) + .andExpect(content().string(CoreMatchers.containsString("Attribute submitted successfully"))); + } + + @Test + public void complexAttributeInstallationCheck() throws Exception { + this.mvc.perform(post("/attribs") + .param("zoneName", "/") + .param("attributeName", "a") + .param("attributeType", "List") + .param("attributeComplexType", "List, Set, Int") + .param("valueString", "[[1]]")) + .andExpect(status().isOk()) + .andExpect(content().contentType("text/html;charset=UTF-8")) + .andExpect(content().string(CoreMatchers.containsString("Attribute submitted successfully"))); } @Test public void numericalRESTApiCheck() throws Exception { - // TODO + Thread.sleep(10000); + this.mvc.perform(get("/attribNumValues") + .accept(MediaType.TEXT_PLAIN)) + .andExpect(status().isOk()) + .andExpect(content().string(CoreMatchers.containsString("num_processes"))); } @Test public void allValuesRESTApiCheck() throws Exception { - // TODO + Thread.sleep(10000); + mvc.perform(get("/attribAllValues") + .accept(MediaType.TEXT_PLAIN)) + .andExpect(status().isOk()) + .andExpect(content().string(CoreMatchers.containsString("contacts"))); } } -- cgit v1.2.3