497N/A/*
497N/A * CDDL HEADER START
497N/A *
497N/A * The contents of this file are subject to the terms of the
497N/A * Common Development and Distribution License (the "License").
497N/A * You may not use this file except in compliance with the License.
497N/A *
497N/A * See LICENSE.txt included in this distribution for the specific
497N/A * language governing permissions and limitations under the License.
497N/A *
497N/A * When distributing Covered Code, include this CDDL HEADER in each
497N/A * file and include the License file at LICENSE.txt.
497N/A * If applicable, add the following below this CDDL HEADER, with the
497N/A * fields enclosed by brackets "[]" replaced with your own identifying
497N/A * information: Portions Copyright [yyyy] [name of copyright owner]
497N/A *
497N/A * CDDL HEADER END
497N/A */
497N/A
497N/A/*
1043N/A * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
497N/A */
497N/A
497N/Apackage org.opensolaris.opengrok.management.client;
497N/A
497N/Aimport java.io.File;
497N/Aimport java.net.InetAddress;
497N/Aimport java.util.Properties;
497N/Aimport org.junit.After;
497N/Aimport org.junit.Before;
497N/Aimport org.junit.Test;
497N/Aimport org.opensolaris.opengrok.management.OGAgent;
497N/Aimport org.opensolaris.opengrok.util.FileUtilities;
497N/Aimport static org.junit.Assert.*;
497N/A
497N/Apublic class AgentConnectionTest {
497N/A
497N/A private Properties savedProperties;
497N/A
497N/A @Before
497N/A public void setUp() {
497N/A savedProperties = (Properties) System.getProperties().clone();
497N/A }
497N/A
497N/A @After
497N/A public void tearDown() {
497N/A if (savedProperties != null) {
497N/A System.setProperties(savedProperties);
497N/A }
497N/A }
497N/A
497N/A @Test
497N/A public void testAgentConnection() throws Exception {
497N/A File logDir = FileUtilities.createTemporaryDirectory("logdir");
497N/A System.setProperty("org.opensolaris.opengrok.management.logging.path",
497N/A logDir.getAbsolutePath());
682N/A// OGAgent oga = new OGAgent();
682N/A// oga.runOGA();
682N/A OGAgent.main(new String[0]);
1043N/A String host = InetAddress.getLocalHost().getHostName();
1043N/A String url =
1043N/A "service:jmx:rmi://" + host + ":9292/jndi/rmi://" +
1043N/A host + ":9293/opengrok";
497N/A AgentConnection ac = new AgentConnection(url);
497N/A assertFalse("Shouldn't be connected", ac.isConnected());
497N/A assertEquals(url, ac.getAgentURL());
497N/A
497N/A ac.connect();
497N/A ac.registerListener();
497N/A assertTrue("Should be connected", ac.isConnected());
497N/A assertNotNull(ac.getMBeanServerConnection());
497N/A
497N/A ac.unregister();
497N/A
497N/A ac.reconnect(1);
497N/A assertTrue("Not connected after reconnect", ac.isConnected());
497N/A
497N/A FileUtilities.removeDirs(logDir);
497N/A }
497N/A
497N/A}