package org.jolokia.client.request;

/*
 * Copyright 2009-2013 Roland Huss
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import javax.management.MalformedObjectNameException;

import org.jolokia.client.exception.JolokiaException;
import org.jolokia.client.response.JolokiaReadResponse;
import org.jolokia.it.core.ItSetup;
import org.testng.annotations.Test;

import static org.testng.Assert.*;

/**
 * @author roland
 * @since 13.01.13
 */
public class ClientJsr160HiddenTest extends AbstractClientIntegrationTest {

    @Test
    public void hiddenMBeanNotAvailableForJSR160() throws MalformedObjectNameException {
        try {
            JolokiaReadRequest request = new JolokiaReadRequest(getTargetProxyConfig(),
                                                        ItSetup.JOLOKIA_IT_DOMAIN_HIDDEN + ":type=attribute","LongSeconds");
            jolokiaClient.execute(request);
            fail("Exception should have been thrown");
        } catch (JolokiaException exp) {
            assertTrue(exp.getMessage().contains("Error: jolokia.it.hidden:type=attribute"));
        }

    }

    @Test
    public void hiddenMBeanAvailableForJolokia() throws MalformedObjectNameException, JolokiaException {
        JolokiaReadRequest request = new JolokiaReadRequest(ItSetup.JOLOKIA_IT_DOMAIN + ":type=attribute","LongSeconds");
        JolokiaReadResponse response = jolokiaClient.execute(request);
        assertNotNull(response.getValue());
    }
}
