2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2024 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.drools.pooling.message;
24 import static org.junit.jupiter.api.Assertions.assertEquals;
25 import static org.junit.jupiter.api.Assertions.assertNull;
29 import org.junit.jupiter.api.Test;
32 * Superclass used to test subclasses of {@link MessageWithAssignments}.
34 * @param <T> type of {@link MessageWithAssignments} subclass that this tests
38 public abstract class SupportMessageWithAssignmentsTester<T extends MessageWithAssignments>
39 extends SupportBasicMessageTester<T> {
40 // values set by makeValidMessage()
41 public static final String[] VALID_ARRAY = {VALID_HOST, VALID_HOST + "_xxx"};
42 public static final BucketAssignments VALID_ASGN = new BucketAssignments(VALID_ARRAY);
45 * {@code True} if {@code null} assignments are allowed, {@code false}
48 private boolean nullAssignments;
53 * @param subclazz subclass of {@link MessageWithAssignments} being tested
55 public SupportMessageWithAssignmentsTester(Class<T> subclazz) {
60 public void testCheckValidity_InvalidFields() {
61 // null source (i.e., superclass field)
62 expectCheckValidityFailure(msg -> msg.setSource(null));
65 expectCheckValidityFailure(msg -> msg.setAssignments(new BucketAssignments(new String[0])));
68 String[] invalidAssignment = {"abc", null};
69 expectCheckValidityFailure(msg -> msg.setAssignments(new BucketAssignments(invalidAssignment)));
73 public void testGetAssignments_testSetAssignments() {
74 MessageWithAssignments msg = makeValidMessage();
77 assertEquals(VALID_ASGN, msg.getAssignments());
79 BucketAssignments asgn = new BucketAssignments();
80 msg.setAssignments(asgn);
81 assertEquals(asgn, msg.getAssignments());
85 public void testDefaultConstructorFields(T msg) {
86 super.testDefaultConstructorFields(msg);
88 assertNull(msg.getAssignments());
92 public void testValidFields(T msg) {
93 super.testValidFields(msg);
95 if (nullAssignments) {
96 assertNull(msg.getAssignments());
99 assertEquals(VALID_ASGN, msg.getAssignments());