diff options
author | Jim Hahn <jrh3@att.com> | 2020-02-20 19:08:55 -0500 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-02-21 20:33:06 -0500 |
commit | 7f69c5ca0a6f6018166f8fee3e811edf4dee1eb8 (patch) | |
tree | e57ab3105adbe0752b30e0e0a60ea43588cfb384 /models-interactions/model-actors/actor.test/src/test | |
parent | 3c8c5b2994e3f132385f0341283bc271e13cdb25 (diff) |
Change payload to Map<String,Object> so it's more versatile
This was supposed to be two separate commits, but I goofed something.
Added guard query to Operation superclass. Modified VfModuleCreate
to store the VF count, pass it to the guard, and bump it once the
create completes successfully.
Added code to check Actors for proper plug-in to ActorService.
Renamed "operation" property to "operations", to be more consistent
with other parameters (e.g., TopicParameterGroup).
The META-INF/services files for the actors had mixed case, which
did not match the package name of the Actor class, preventing the
ServiceLoader from recognizing them. Also modified the ActorService
to skip any that cannot actually be loaded, for whatever reason
(e.g., not in the classpath).
Issue-ID: POLICY-1625
Signed-off-by: Jim Hahn <jrh3@att.com>
Change-Id: Ifa97744543f2866cc553138ec5ec644b033de780
Diffstat (limited to 'models-interactions/model-actors/actor.test/src/test')
9 files changed, 264 insertions, 0 deletions
diff --git a/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicActorTest.java b/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicActorTest.java new file mode 100644 index 000000000..ef9b37ba6 --- /dev/null +++ b/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicActorTest.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.controlloop.actor.test; + +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.Test; + +public class BasicActorTest extends BasicActor { + + @Test + public void testVerifyActorService_testStartOtherServices_testStopOtherServices() { + // mostly empty service + verifyActorService(DummyActor.NAME, "service.yaml"); + + // service with Topics and HTTP Clients + verifyActorService(DummyActor.NAME, "serviceFull.yaml"); + + assertThatIllegalArgumentException() + .isThrownBy(() -> verifyActorService(DummyActor.NAME, "serviceInvalidHttp.yaml")); + + assertThatIllegalArgumentException() + .isThrownBy(() -> verifyActorService(DummyActor.NAME, "serviceMissingActors.yaml")); + + // config file not found + assertThatThrownBy(() -> verifyActorService(DummyActor.NAME, "file-not-found.yaml")); + } +} diff --git a/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicOperationTest.java b/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicOperationTest.java index 60bb00892..5eb35e9d0 100644 --- a/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicOperationTest.java +++ b/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicOperationTest.java @@ -27,11 +27,16 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import java.util.Map; +import java.util.concurrent.CompletableFuture; import org.junit.Before; import org.junit.Test; +import org.onap.policy.aai.AaiCqResponse; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; import org.onap.policy.controlloop.actorserviceprovider.Util; +import org.onap.policy.controlloop.actorserviceprovider.impl.OperationPartial; +import org.onap.policy.controlloop.policy.PolicyResult; public class BasicOperationTest { private static final String ACTOR = "my-actor"; @@ -65,6 +70,12 @@ public class BasicOperationTest { assertNotNull(oper.context); assertNotNull(oper.outcome); assertNotNull(oper.executor); + assertNotNull(oper.guardOperation); + + CompletableFuture<OperationOutcome> future = oper.service.getActor(OperationPartial.GUARD_ACTOR_NAME) + .getOperator(OperationPartial.GUARD_OPERATION_NAME).buildOperation(null).start(); + assertTrue(future.isDone()); + assertEquals(PolicyResult.SUCCESS, future.get().getResult()); } @Test @@ -97,4 +108,14 @@ public class BasicOperationTest { Map<String, Object> map = Util.translateToMap("", ResourceUtils.getResourceAsString("actual.json")); oper.verifyRequest("expected.json", map, "svc-request-id", "vnf-id"); } + + @Test + public void testProvideCqResponse() throws Exception { + AaiCqResponse cq = new AaiCqResponse("{}"); + oper.provideCqResponse(cq); + + assertSame(cq, oper.context.getProperty(AaiCqResponse.CONTEXT_KEY)); + assertTrue(oper.cqFuture.isDone()); + assertEquals(PolicyResult.SUCCESS, oper.cqFuture.get().getResult()); + } } diff --git a/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/DummyActor.java b/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/DummyActor.java new file mode 100644 index 000000000..c862a18b7 --- /dev/null +++ b/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/DummyActor.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.controlloop.actor.test; + +import org.onap.policy.controlloop.actorserviceprovider.impl.ActorImpl; + +public class DummyActor extends ActorImpl { + public static final String NAME = "MyActor"; + public static final String MY_OPERATION1 = "MyOperationA"; + public static final String MY_OPERATION2 = "MyOperationB"; + + /** + * Constructs the object. + */ + public DummyActor() { + super(NAME); + + addOperator(new DummyOperator(NAME, MY_OPERATION1)); + addOperator(new DummyOperator(NAME, MY_OPERATION2)); + } +} diff --git a/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/DummyOperator.java b/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/DummyOperator.java new file mode 100644 index 000000000..efd3b6500 --- /dev/null +++ b/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/DummyOperator.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.controlloop.actor.test; + +import org.onap.policy.controlloop.actorserviceprovider.Operation; +import org.onap.policy.controlloop.actorserviceprovider.impl.OperatorPartial; +import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; + +public class DummyOperator extends OperatorPartial { + + public DummyOperator(String actorName, String name) { + super(actorName, name); + } + + @Override + public Operation buildOperation(ControlLoopOperationParams params) { + return null; + } +} diff --git a/models-interactions/model-actors/actor.test/src/test/resources/META-INF/services/org.onap.policy.controlloop.actorserviceprovider.spi.Actor b/models-interactions/model-actors/actor.test/src/test/resources/META-INF/services/org.onap.policy.controlloop.actorserviceprovider.spi.Actor new file mode 100644 index 000000000..f9c3bddfd --- /dev/null +++ b/models-interactions/model-actors/actor.test/src/test/resources/META-INF/services/org.onap.policy.controlloop.actorserviceprovider.spi.Actor @@ -0,0 +1 @@ +org.onap.policy.controlloop.actor.test.DummyActor
\ No newline at end of file diff --git a/models-interactions/model-actors/actor.test/src/test/resources/service.yaml b/models-interactions/model-actors/actor.test/src/test/resources/service.yaml new file mode 100644 index 000000000..49de7da51 --- /dev/null +++ b/models-interactions/model-actors/actor.test/src/test/resources/service.yaml @@ -0,0 +1,23 @@ +# +# ============LICENSE_START====================================================== +# ONAP +# =============================================================================== +# Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. +# =============================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END======================================================== +# +actors: + MyActor: + MyOperationA: {} + MyOperationB: {}
\ No newline at end of file diff --git a/models-interactions/model-actors/actor.test/src/test/resources/serviceFull.yaml b/models-interactions/model-actors/actor.test/src/test/resources/serviceFull.yaml new file mode 100644 index 000000000..9818215be --- /dev/null +++ b/models-interactions/model-actors/actor.test/src/test/resources/serviceFull.yaml @@ -0,0 +1,42 @@ +# +# ============LICENSE_START====================================================== +# ONAP +# =============================================================================== +# Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. +# =============================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END======================================================== +# +httpClients: +- clientName: my-client + hostname: localhost + port: 80 + basePath: base-url + managed: true +topics: + topicSources: + - topicCommInfrastructure: NOOP + topic: my-source + servers: + - localhost + managed: true + topicSinks: + - topicCommInfrastructure: NOOP + topic: my-sink + servers: + - localhost + managed: true +actors: + MyActor: + MyOperationA: {} + MyOperationB: {}
\ No newline at end of file diff --git a/models-interactions/model-actors/actor.test/src/test/resources/serviceInvalidHttp.yaml b/models-interactions/model-actors/actor.test/src/test/resources/serviceInvalidHttp.yaml new file mode 100644 index 000000000..b31e8e81e --- /dev/null +++ b/models-interactions/model-actors/actor.test/src/test/resources/serviceInvalidHttp.yaml @@ -0,0 +1,29 @@ +# +# ============LICENSE_START====================================================== +# ONAP +# =============================================================================== +# Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. +# =============================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END======================================================== +# +httpClients: +- clientName: my-client + hostname: localhost + port: 80 + serializationProvider: unknown.class.name + managed: true +actors: + MyActor: + MyOperationA: {} + MyOperationB: {}
\ No newline at end of file diff --git a/models-interactions/model-actors/actor.test/src/test/resources/serviceMissingActors.yaml b/models-interactions/model-actors/actor.test/src/test/resources/serviceMissingActors.yaml new file mode 100644 index 000000000..0eec84ea4 --- /dev/null +++ b/models-interactions/model-actors/actor.test/src/test/resources/serviceMissingActors.yaml @@ -0,0 +1,25 @@ +# +# ============LICENSE_START====================================================== +# ONAP +# =============================================================================== +# Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. +# =============================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END======================================================== +# +httpClients: +- clientName: my-client + hostname: localhost + port: 80 + basePath: base-url + managed: true
\ No newline at end of file |