Esempio n. 1
0
 protected void internalStart() throws Exception {
   Configuration pluginConfig = context.getPluginConfiguration();
   String connectionTypeDescriptorClassName =
       pluginConfig.getSimple(JMXDiscoveryComponent.CONNECTION_TYPE).getStringValue();
   if (JMXDiscoveryComponent.PARENT_TYPE.equals(connectionTypeDescriptorClassName)) {
     // Our parent is itself a JMX component, so just reuse its connection.
     this.connection = ((JMXComponent) context.getParentResourceComponent()).getEmsConnection();
     this.connectionProvider = this.connection.getConnectionProvider();
   } else {
     this.connectionProvider =
         ConnectionProviderFactory.createConnectionProvider(
             pluginConfig, this.context.getNativeProcess(), this.context.getTemporaryDirectory());
     this.connection = this.connectionProvider.connect();
     this.connection.loadSynchronous(false);
   }
 }
Esempio n. 2
0
  /**
   * Start the resource connection
   *
   * @see
   *     org.rhq.core.pluginapi.inventory.ResourceComponent#start(org.rhq.core.pluginapi.inventory.ResourceContext)
   */
  public void start(ResourceContext context) throws InvalidPluginConfigurationException, Exception {
    this.context = context;
    pluginConfiguration = context.getPluginConfiguration();

    if (!(context.getParentResourceComponent() instanceof BaseComponent)) {
      host = pluginConfiguration.getSimpleValue("hostname", LOCALHOST);
      String portString = pluginConfiguration.getSimpleValue("port", DEFAULT_HTTP_MANAGEMENT_PORT);
      port = Integer.parseInt(portString);
      connection = new ASConnection(host, port);
    } else {
      connection = ((BaseComponent) context.getParentResourceComponent()).getASConnection();
    }

    path = pluginConfiguration.getSimpleValue("path", null);
    address = new Address(path);
    key = context.getResourceKey();

    myServerName =
        context.getResourceKey().substring(context.getResourceKey().lastIndexOf("/") + 1);
  }
Esempio n. 3
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  @Test
  public void loadResourceConfigurationWithType() throws Exception {
    // tell the method story as it happens: mock or create dependencies and configure
    // those dependencies to get the method under test to completion.
    ResourceContext mockResourceContext = mock(ResourceContext.class);

    ResourceType mockResourceType = mock(ResourceType.class);
    when(mockResourceContext.getResourceType()).thenReturn(mockResourceType);

    ConfigurationDefinition mockConfigurationDefinition = mock(ConfigurationDefinition.class);
    when(mockResourceType.getResourceConfigurationDefinition())
        .thenReturn(mockConfigurationDefinition);

    ConfigurationTemplate mockConfigurationTemplate = mock(ConfigurationTemplate.class);
    when(mockConfigurationDefinition.getDefaultTemplate()).thenReturn(mockConfigurationTemplate);

    Configuration mockConfiguration = mock(Configuration.class);
    when(mockConfigurationTemplate.getConfiguration()).thenReturn(mockConfiguration);

    Property mockProperty = mock(Property.class);
    when(mockConfiguration.get(eq("__type"))).thenReturn(mockProperty);

    Map<String, PropertyDefinition> mockMap = (Map<String, PropertyDefinition>) mock(Map.class);
    when(mockConfigurationDefinition.getPropertyDefinitions()).thenReturn(mockMap);

    ConfigurationLoadDelegate mockConfigurationLoadDelegate = mock(ConfigurationLoadDelegate.class);
    PowerMockito.whenNew(ConfigurationLoadDelegate.class)
        .withParameterTypes(ConfigurationDefinition.class, ASConnection.class, Address.class)
        .withArguments(
            any(ConfigurationDefinition.class), any(ASConnection.class), any(Address.class))
        .thenReturn(mockConfigurationLoadDelegate);

    when(mockConfigurationLoadDelegate.loadResourceConfiguration()).thenReturn(mockConfiguration);

    PropertySimple pathPropertySimple = new PropertySimple("path", "abc=def,xyz=test1");
    when(mockConfiguration.get(eq("path"))).thenReturn(pathPropertySimple);
    when(mockResourceContext.getPluginConfiguration()).thenReturn(mockConfiguration);

    ASConnection mockASConnection = mock(ASConnection.class);

    PropertySimple typePropertySimple = new PropertySimple("__type", "xyz");
    PowerMockito.whenNew(PropertySimple.class)
        .withParameterTypes(String.class, Object.class)
        .withArguments(eq("__type"), eq("xyz"))
        .thenReturn(typePropertySimple);

    // create object to test and inject required dependencies
    TemplatedComponent objectUnderTest = new TemplatedComponent();

    objectUnderTest.context = mockResourceContext;
    objectUnderTest.testConnection = mockASConnection;

    // run code under test
    Configuration result = objectUnderTest.loadResourceConfiguration();

    // verify the results (Assert and mock verification)
    Assert.assertEquals(result, mockConfiguration);

    verify(mockMap, times(1)).remove(eq("__type"));
    verify(mockConfiguration, times(1)).get(eq("__type"));
    verify(mockConfiguration, never()).get(eq("__name"));
    verify(mockConfiguration, times(1)).get(eq("path"));
    verify(mockConfiguration, times(1)).put(eq(typePropertySimple));

    PowerMockito.verifyNew(PropertySimple.class).withArguments(eq("__type"), eq("xyz"));
    PowerMockito.verifyNew(ConfigurationLoadDelegate.class)
        .withArguments(
            any(ConfigurationDefinition.class), eq(mockASConnection), any(Address.class));
  }