Validate request bodies in controller methods
[portal/ric-dashboard.git] / dashboard / webapp-backend / src / test / java / org / oransc / ric / portal / dashboard / controller / AppManagerControllerTest.java
index 52a383e..0132c19 100644 (file)
@@ -24,20 +24,21 @@ import java.net.URI;
 
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
-import org.oransc.ric.plt.appmgr.client.model.AllDeployedXapps;
-import org.oransc.ric.plt.appmgr.client.model.AllXappConfig;
-import org.oransc.ric.plt.appmgr.client.model.XAppConfig;
-import org.oransc.ric.plt.appmgr.client.model.Xapp;
-import org.oransc.ric.plt.appmgr.client.model.XappDescriptor;
 import org.oransc.ric.portal.dashboard.DashboardConstants;
 import org.oransc.ric.portal.dashboard.config.RICInstanceMockConfiguration;
 import org.oransc.ric.portal.dashboard.model.DashboardDeployableXapps;
 import org.oransc.ric.portal.dashboard.model.SuccessTransport;
+import org.oransc.ricplt.appmgr.client.model.AllDeployedXapps;
+import org.oransc.ricplt.appmgr.client.model.AllXappConfig;
+import org.oransc.ricplt.appmgr.client.model.XAppConfig;
+import org.oransc.ricplt.appmgr.client.model.Xapp;
+import org.oransc.ricplt.appmgr.client.model.XappDescriptor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpMethod;
 import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestClientException;
 
 public class AppManagerControllerTest extends AbstractControllerTest {
 
@@ -102,9 +103,15 @@ public class AppManagerControllerTest extends AbstractControllerTest {
                URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
                                RICInstanceMockConfiguration.INSTANCE_KEY_1, AppManagerController.XAPPS_METHOD);
                logger.info("Invoking {}", uri);
-               XappDescriptor descr = new XappDescriptor();
+               XappDescriptor descr = new XappDescriptor().xappName("app");
                Xapp app = testRestTemplateAdminRole().postForObject(uri, descr, Xapp.class);
+               Assertions.assertNotNull(app);
                Assertions.assertFalse(app.getName().isEmpty());
+
+               // An invalid request must be rejected
+               Assertions.assertThrows(RestClientException.class, () -> {
+                       testRestTemplateAdminRole().postForObject(uri, new XappDescriptor(), Xapp.class);
+               });
        }
 
        @Test