2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.plugins.context.test.locking;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.fail;
28 import java.io.IOException;
30 import org.apache.curator.test.TestingServer;
31 import org.junit.After;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.policy.apex.context.ContextException;
35 import org.onap.policy.apex.context.parameters.ContextParameters;
36 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
37 import org.onap.policy.apex.plugins.context.locking.curator.CuratorLockManager;
38 import org.onap.policy.apex.plugins.context.locking.curator.CuratorLockManagerParameters;
40 public class CuratorManagerTest {
41 // Zookeeper test server
42 TestingServer zkTestServer;
45 public void beforeTest() throws Exception {
46 zkTestServer = new TestingServer(62181);
50 public void afterTest() throws IOException {
55 public void testCuratorManagerConfigProperty() {
56 final ContextParameters contextParameters = new ContextParameters();
57 contextParameters.setLockManagerParameters(new CuratorLockManagerParameters());
59 ((CuratorLockManagerParameters) contextParameters.getLockManagerParameters()).setZookeeperAddress(null);
62 final CuratorLockManager curatorManager = new CuratorLockManager();
63 curatorManager.init(new AxArtifactKey());
64 assertNull(curatorManager);
65 } catch (final ContextException e) {
66 assertEquals(e.getMessage(),
67 "could not set up Curator locking, check if the curator Zookeeper address parameter is set correctly");
70 ((CuratorLockManagerParameters) contextParameters.getLockManagerParameters()).setZookeeperAddress("zooby");
73 final CuratorLockManager curatorManager = new CuratorLockManager();
74 curatorManager.init(new AxArtifactKey());
75 fail("Curator manager test should fail");
76 } catch (final ContextException e) {
77 assertEquals(e.getMessage(),
78 "could not connect to Zookeeper server at \"zooby\", see error log for details");
81 ((CuratorLockManagerParameters) contextParameters.getLockManagerParameters())
82 .setZookeeperAddress("localhost:62181");
85 final CuratorLockManager curatorManager0 = new CuratorLockManager();
86 curatorManager0.init(new AxArtifactKey());
87 assertNotNull(curatorManager0);
89 final CuratorLockManager curatorManager1 = new CuratorLockManager();
90 curatorManager1.init(new AxArtifactKey());
91 assertNotNull(curatorManager1);
93 curatorManager0.shutdown();
94 curatorManager1.shutdown();
95 } catch (final ContextException e) {