Jian Li
Committed by Gerrit Code Review

Not allow null value for all control metrics, revise unit test

Current implementation allows null value from REST API.
Null metric value leads the metrics database to not store the value
properly. This commit tries to fix this issue.

Change-Id: I82a5fd0d11671db4d2136a3fc40090b7684ba91a
...@@ -57,6 +57,15 @@ public class ControlMetricsCollectorResourceTest extends JerseyTest { ...@@ -57,6 +57,15 @@ public class ControlMetricsCollectorResourceTest extends JerseyTest {
57 private static final String PREFIX = "collector"; 57 private static final String PREFIX = "collector";
58 58
59 /** 59 /**
60 + * Constructs a control metrics collector resource test instance.
61 + */
62 + public ControlMetricsCollectorResourceTest() {
63 + super(new WebAppDescriptor.Builder("javax.ws.rs.Application",
64 + CPManWebApplication.class.getCanonicalName())
65 + .servletClass(ServletContainer.class).build());
66 + }
67 +
68 + /**
60 * Sets up the global values for all the tests. 69 * Sets up the global values for all the tests.
61 */ 70 */
62 @Before 71 @Before
...@@ -67,6 +76,9 @@ public class ControlMetricsCollectorResourceTest extends JerseyTest { ...@@ -67,6 +76,9 @@ public class ControlMetricsCollectorResourceTest extends JerseyTest {
67 BaseResource.setServiceDirectory(testDirectory); 76 BaseResource.setServiceDirectory(testDirectory);
68 } 77 }
69 78
79 + /**
80 + * Tests CPU metrics POST through REST API.
81 + */
70 @Test 82 @Test
71 public void testCpuMetricsPost() { 83 public void testCpuMetricsPost() {
72 mockControlPlaneMonitorService.updateMetric(anyObject(), anyInt(), 84 mockControlPlaneMonitorService.updateMetric(anyObject(), anyInt(),
...@@ -76,6 +88,9 @@ public class ControlMetricsCollectorResourceTest extends JerseyTest { ...@@ -76,6 +88,9 @@ public class ControlMetricsCollectorResourceTest extends JerseyTest {
76 basePostTest("cpu-metrics-post.json", PREFIX + "/cpu_metrics"); 88 basePostTest("cpu-metrics-post.json", PREFIX + "/cpu_metrics");
77 } 89 }
78 90
91 + /**
92 + * Tests memory metrics POST through REST API.
93 + */
79 @Test 94 @Test
80 public void testMemoryMetricsPost() { 95 public void testMemoryMetricsPost() {
81 mockControlPlaneMonitorService.updateMetric(anyObject(), anyInt(), 96 mockControlPlaneMonitorService.updateMetric(anyObject(), anyInt(),
...@@ -85,16 +100,22 @@ public class ControlMetricsCollectorResourceTest extends JerseyTest { ...@@ -85,16 +100,22 @@ public class ControlMetricsCollectorResourceTest extends JerseyTest {
85 basePostTest("memory-metrics-post.json", PREFIX + "/memory_metrics"); 100 basePostTest("memory-metrics-post.json", PREFIX + "/memory_metrics");
86 } 101 }
87 102
103 + /**
104 + * Tests disk metrics POST through REST API.
105 + */
88 @Test 106 @Test
89 - public void testDiskMetricsWithNullName() { 107 + public void testDiskMetrics() {
90 mockControlPlaneMonitorService.updateMetric(anyObject(), anyInt(), anyString()); 108 mockControlPlaneMonitorService.updateMetric(anyObject(), anyInt(), anyString());
91 expectLastCall().times(4); 109 expectLastCall().times(4);
92 replay(mockControlPlaneMonitorService); 110 replay(mockControlPlaneMonitorService);
93 basePostTest("disk-metrics-post.json", PREFIX + "/disk_metrics"); 111 basePostTest("disk-metrics-post.json", PREFIX + "/disk_metrics");
94 } 112 }
95 113
114 + /**
115 + * Tests network metrics POST through REST API.
116 + */
96 @Test 117 @Test
97 - public void testNetworkMetricsWithNullName() { 118 + public void testNetworkMetrics() {
98 mockControlPlaneMonitorService.updateMetric(anyObject(), anyInt(), anyString()); 119 mockControlPlaneMonitorService.updateMetric(anyObject(), anyInt(), anyString());
99 expectLastCall().times(8); 120 expectLastCall().times(8);
100 replay(mockControlPlaneMonitorService); 121 replay(mockControlPlaneMonitorService);
...@@ -123,12 +144,6 @@ public class ControlMetricsCollectorResourceTest extends JerseyTest { ...@@ -123,12 +144,6 @@ public class ControlMetricsCollectorResourceTest extends JerseyTest {
123 assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK)); 144 assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK));
124 } 145 }
125 146
126 - public ControlMetricsCollectorResourceTest() {
127 - super(new WebAppDescriptor.Builder("javax.ws.rs.Application",
128 - CPManWebApplication.class.getCanonicalName())
129 - .servletClass(ServletContainer.class).build());
130 - }
131 -
132 /** 147 /**
133 * Assigns an available port for the test. 148 * Assigns an available port for the test.
134 * 149 *
......