Merge "Added check of callback URL in service registration"
authorJohn Keeney <John.Keeney@est.tech>
Thu, 9 Apr 2020 08:09:15 +0000 (08:09 +0000)
committerGerrit Code Review <gerrit@o-ran-sc.org>
Thu, 9 Apr 2020 08:09:15 +0000 (08:09 +0000)
1  2 
policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java

@@@ -184,7 -184,7 +184,7 @@@ public class ApplicationTest 
              ric.getLock().lockBlocking(LockType.EXCLUSIVE);
              ric.getLock().unlockBlocking();
              assertThat(ric.getLock().getLockCounter()).isEqualTo(0);
 -            assertThat(ric.getState()).isEqualTo(Ric.RicState.IDLE);
 +            assertThat(ric.getState()).isEqualTo(Ric.RicState.AVAILABLE);
          }
      }
  
  
      @Test
      public void testSynchronization() throws Exception {
 -        addRic("ric").setState(Ric.RicState.UNDEFINED);
 +        addRic("ric").setState(Ric.RicState.UNAVAILABLE);
          String ricName = "ric";
          Policy policy2 = addPolicy("policyId2", "typeName", "service", ricName);
  
          Policy policy = addPolicy(policyId, "typeName", "service", ricName); // This should be created in the RIC
          supervision.checkAllRics(); // The created policy should be put in the RIC
          await().untilAsserted(() -> RicState.SYNCHRONIZING.equals(rics.getRic(ricName).getState()));
 -        await().untilAsserted(() -> RicState.IDLE.equals(rics.getRic(ricName).getState()));
 +        await().untilAsserted(() -> RicState.AVAILABLE.equals(rics.getRic(ricName).getState()));
  
          Policies ricPolicies = getA1Client(ricName).getPolicies();
          assertThat(ricPolicies.size()).isEqualTo(1);
  
          String url = putPolicyUrl(serviceName, ricName, policyTypeName, policyInstanceId);
          final String policyBody = jsonString();
 -        this.rics.getRic(ricName).setState(Ric.RicState.IDLE);
 +        this.rics.getRic(ricName).setState(Ric.RicState.AVAILABLE);
  
          restClient().put(url, policyBody).block();
  
          url = putPolicyUrl(serviceName, ricName, policyTypeName, policyInstanceId);
          this.rics.getRic(ricName).setState(Ric.RicState.SYNCHRONIZING);
          testErrorCode(restClient().put(url, policyBody), HttpStatus.LOCKED);
 -        this.rics.getRic(ricName).setState(Ric.RicState.IDLE);
 +        this.rics.getRic(ricName).setState(Ric.RicState.AVAILABLE);
      }
  
      @Test
          testErrorCode(restClient().put("/service", "crap"), HttpStatus.BAD_REQUEST);
          testErrorCode(restClient().put("/service", "{}"), HttpStatus.BAD_REQUEST);
          testErrorCode(restClient().put("/service", createServiceJson("name", -123)), HttpStatus.BAD_REQUEST);
+         testErrorCode(restClient().put("/service", createServiceJson("name", 0, "missing.portandprotocol.com")),
+             HttpStatus.BAD_REQUEST);
  
          // GET non existing servive
          testErrorCode(restClient().get("/services?name=XXX"), HttpStatus.NOT_FOUND);
      }
  
      private String createServiceJson(String name, long keepAliveIntervalSeconds) {
-         ServiceRegistrationInfo service = new ServiceRegistrationInfo(name, keepAliveIntervalSeconds, "callbackUrl");
+         return createServiceJson(name, keepAliveIntervalSeconds, "https://examples.javacodegeeks.com/core-java/");
+     }
+     private String createServiceJson(String name, long keepAliveIntervalSeconds, String url) {
+         ServiceRegistrationInfo service = new ServiceRegistrationInfo(name, keepAliveIntervalSeconds, url);
  
          String json = gson.toJson(service);
          return json;
              .controllerName("") //
              .build();
          Ric ric = new Ric(conf);
 -        ric.setState(Ric.RicState.IDLE);
 +        ric.setState(Ric.RicState.AVAILABLE);
          this.rics.put(ric);
          return ric;
      }