// Copyright 2014 Boundary, Inc.
//
// 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.

package com.boundary.plugin.sdk.jmx;

import java.io.IOException;
import java.util.ArrayList;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.boundary.plugin.sdk.MetricDefinition;
import com.boundary.plugin.sdk.MetricDefinitionList;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class MBeansTransformerTest {
	
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	private MetricDefinitionTransform transform;
	private JMXClient client;
	private MBeansTransformer<MetricDefinitionList> transformer;

	@Before
	public void setUp() throws Exception {
		transform = new MetricDefinitionTransform();
		client = new JMXClient();
		client.connect("localhost", 9991);
		transformer = new MBeansTransformer<MetricDefinitionList>(client,transform,"FOO");
	}

	@After
	public void tearDown() throws Exception {

	}

	@Test
	public void testMetricDefinitionConstructor() {
		MetricDefinitionTransform transform = new MetricDefinitionTransform();
		JMXClient client = new JMXClient();
		client.connect("localhost", 9991);
		MBeansTransformer<MetricDefinitionList> transformer = new MBeansTransformer<MetricDefinitionList>(client,transform,"FOO");
		transformer.transform();
		
		MetricDefinitionList list = transform.getMetricList();
		ArrayList<MetricDefinition> a = list.getResult();
		
		for (MetricDefinition def : a) {
			System.out.println(def);
		}

	}

	@Test
	public void testMetricDefinitionTransform() {
		transformer.transform();
		MetricDefinitionList list = transform.getMetricList();

		ObjectMapper mapper = new ObjectMapper();
		try {
			mapper.writeValue(System.out,list);
		} catch (JsonGenerationException e) {
			e.printStackTrace();
		} catch (JsonMappingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
	
	@Test
	public void testMBeansTransformer() {
		MBeanTransform<MBeanMap> transform = new MBeanMapTransform();
		JMXClient client = new JMXClient();
		client.connect("localhost", 9991);
		MBeansTransformer<MBeanMap> transformer = new MBeansTransformer<MBeanMap>(client,transform,"FOO");
		transformer.transform();
		
		MBeanMap map = transformer.export();
		
		for (MBeanEntry entry : map.getMap()) {
			System.out.println(entry);
		}
		
		ObjectMapper mapper = new ObjectMapper();
		try {
			mapper.writeValue(System.out,map);
		} catch (JsonGenerationException e) {
			e.printStackTrace();
		} catch (JsonMappingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

@@ -2120,33 +2120,29 @@
 ransform.get
-MetricLis
+Expor
 t();%0A%09%09Array
@@ -2389,17 +2389,13 @@
 .get
-MetricLis
+Expor
 t();

Change method called to get MetricDefinitionList