5455eae394ba1a7235c886e8e336ecf5ef9bd6b6
[policy/distribution.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.distribution.reception.handling.sdc;
23
24 import java.util.ArrayList;
25 import java.util.Collection;
26
27 import org.onap.policy.distribution.forwarding.PolicyForwarder;
28 import org.onap.policy.distribution.forwarding.PolicyForwardingException;
29 import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
30
31 /**
32  * Class to create a dummy forwarder for test cases.
33  *
34  * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
35  */
36 public class DummyPolicyForwarder implements PolicyForwarder {
37     private int numberOfPoliciesReceived = 0;
38     private Collection<ToscaEntity> policiesReceived = new ArrayList<>();
39
40     /**
41      * {@inheritDoc}.
42      */
43     @Override
44     public void forward(final Collection<ToscaEntity> policies) throws PolicyForwardingException {
45         numberOfPoliciesReceived += policies.size();
46         policiesReceived.addAll(policies);
47     }
48
49     /**
50      * Returns the number of policies received by this forwarder.
51      *
52      * @return the integer value
53      */
54     public int getNumberOfPoliciesReceived() {
55         return numberOfPoliciesReceived;
56     }
57
58     /**
59      * Checks if the forwarder has received a policy with given policy type.
60      *
61      * @param policyType the policy type
62      * @return the boolean result
63      */
64     public boolean receivedPolicyWithGivenType(final String policyType) {
65         for (final ToscaEntity policy : policiesReceived) {
66             if (policy.getName().contains(policyType)) {
67                 return true;
68             }
69         }
70         return false;
71     }
72
73     /**
74      * {@inheritDoc}.
75      */
76     @Override
77     public void configure(final String parameterGroupName) {
78     }
79 }