import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
-import org.oransc.policyagent.clients.A1Client;
import org.oransc.policyagent.configuration.ApplicationConfig;
import org.oransc.policyagent.repository.ImmutablePolicyType;
import org.oransc.policyagent.repository.Policies;
import org.oransc.policyagent.repository.PolicyType;
import org.oransc.policyagent.repository.PolicyTypes;
import org.oransc.policyagent.repository.Rics;
-import org.oransc.policyagent.utils.MockA1Client;
+import org.oransc.policyagent.utils.MockA1ClientFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.context.TestConfiguration;
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
public class MockPolicyAgent {
+ private static final Logger logger = LoggerFactory.getLogger(MockPolicyAgent.class);
+
+ @Autowired
+ Rics rics;
static class MockApplicationConfig extends ApplicationConfig {
@Override
}
/**
- * overrides the BeanFactory
+ * Overrides the BeanFactory.
*/
@TestConfiguration
static class TestBeanFactory {
}
@Bean
- public A1Client getA1Client() {
+ public MockA1ClientFactory getA1ClientFactory() {
PolicyTypes ricTypes = new PolicyTypes();
loadTypes(ricTypes);
- A1Client client = new MockA1Client(ricTypes);
- return client;
+ return new MockA1ClientFactory(ricTypes);
}
@Bean
PolicyType type = ImmutablePolicyType.builder().name(typeName).schema(schema).build();
policyTypes.put(type);
} catch (Exception e) {
- System.out.println("Could not load json schema " + e);
+ logger.error("Could not load json schema ", e);
}
}
}
-
}
@LocalServerPort
private int port;
- private void keepServerAlive() {
- System.out.println("Keeping server alive!");
- try {
- synchronized (this) {
- this.wait();
- }
- } catch (Exception ex) {
- System.out.println("Unexpected: " + ex.toString());
+ private void keepServerAlive() throws InterruptedException {
+ logger.info("Keeping server alive!");
+
+ synchronized (this) {
+ this.wait();
}
+
}
private static String title(String jsonSchema) {
- JsonObject parsedSchema = (JsonObject) new JsonParser().parse(jsonSchema);
+ JsonObject parsedSchema = (JsonObject) JsonParser.parseString(jsonSchema);
String title = parsedSchema.get("title").getAsString();
return title;
}
@Test
+ @SuppressWarnings("squid:S2699") // Tests should include assertions. This test is only for keeping the server
+ // alive,
+ // so it will only be confusing to add an assertion.
public void runMock() throws Exception {
keepServerAlive();
}