2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.pap.main.comm;
23 import static org.assertj.core.api.Assertions.assertThat;
25 import java.sql.SQLIntegrityConstraintViolationException;
26 import org.eclipse.persistence.exceptions.EclipseLinkException;
27 import org.junit.Test;
29 public class PdpStatusMessageHandlerTest {
32 public void testIsDuplicateKeyException() {
37 assertThat(PdpStatusMessageHandler.isDuplicateKeyException(null)).isFalse();
40 assertThat(PdpStatusMessageHandler.isDuplicateKeyException(
44 // cause is also plain
45 assertThat(PdpStatusMessageHandler.isDuplicateKeyException(
51 assertThat(PdpStatusMessageHandler.isDuplicateKeyException(
52 new SQLIntegrityConstraintViolationException()))
56 assertThat(PdpStatusMessageHandler.isDuplicateKeyException(
58 new SQLIntegrityConstraintViolationException())))
61 // eclipselink exception, no internal exception
62 assertThat(PdpStatusMessageHandler.isDuplicateKeyException(
63 new MyEclipseLinkException()))
66 // eclipselink exception, cause is plain
67 assertThat(PdpStatusMessageHandler.isDuplicateKeyException(
68 new MyEclipseLinkException(
72 // eclipselink exception, cause is dup
73 assertThat(PdpStatusMessageHandler.isDuplicateKeyException(
74 new MyEclipseLinkException(
75 new SQLIntegrityConstraintViolationException())))
78 // multiple cause both inside and outside of the eclipselink exception
79 assertThat(PdpStatusMessageHandler.isDuplicateKeyException(
82 new MyEclipseLinkException(
84 new SQLIntegrityConstraintViolationException()))))))
90 public static class MyEclipseLinkException extends EclipseLinkException {
91 private static final long serialVersionUID = 1L;
93 public MyEclipseLinkException() {
97 public MyEclipseLinkException(Exception exception) {
98 setInternalException(exception);