biemond/biemond-wildfly

View on GitHub
spec/unit/puppet_x/wildfly/cli_command_spec.rb

Summary

Maintainability
A
1 hr
Test Coverage
require 'spec_helper'
require 'puppet_x/wildfly/cli_command'

describe PuppetX::Wildfly::CLICommand do
  context 'detyped requests' do
    it 'creates a request for a paramless no parentheses operation' do
      detyped_request = described_class.new(':reload').to_detyped_request

      expect(detyped_request).to eq(:operation => 'reload', :address => [])
    end

    it 'creates a request for a plain operation' do
      detyped_request = described_class.new('reload').to_detyped_request

      expect(detyped_request).to eq(:operation => 'reload', :address => [])
    end

    it 'fails for a request with invalid syntax' do
      expect { described_class.new('/subsystem:invalid') }.to raise_error(RuntimeError)
    end

    it 'creates a request for a paramless operation' do
      detyped_request = described_class.new(':shutdown').to_detyped_request
      expect(detyped_request).to eq(:operation => 'shutdown', :address => [])
    end

    it 'creates a request for a single param operation' do
      detyped_request = described_class.new(':read-attribute(name=server-state)').to_detyped_request
      expect(detyped_request).to eq(:operation => 'read-attribute', :address => [], 'name' => 'server-state')
    end

    it 'creates a request for a multiple param operation' do
      detyped_request = described_class.new(':read-attribute(name=server-state, include-defaults=true)').to_detyped_request
      expect(detyped_request).to eq(:operation => 'read-attribute', :address => [], 'name' => 'server-state', 'include-defaults' => 'true')
    end

    it 'creates a request for a multiple param operation with headers' do
      detyped_request = described_class.new(':read-attribute(name=server-state, include-defaults=true){header=value;header2=otherValue}').to_detyped_request
      expect(detyped_request).to eq(:operation => 'read-attribute', :address => [], 'name' => 'server-state', 'include-defaults' => 'true', 'operation-headers' => { 'header' => 'value', 'header2' => 'otherValue' })
    end

    it 'creates a request with a target address' do
      detyped_request = described_class.new('/subsystem=web:read-operation-names()').to_detyped_request
      expect(detyped_request).to eq(:operation => 'read-operation-names', :address => [{ 'subsystem' => 'web' }])
    end

    it 'creates a request with a complex target address' do
      detyped_request = described_class.new('/subsystem=web/modcluster=configuration:read-operation-names()').to_detyped_request
      expect(detyped_request).to eq(:operation => 'read-operation-names', :address => [{ 'subsystem' => 'web' }, { 'modcluster' => 'configuration' }])
    end

    it 'creates a request with a OBJECT parameter' do
      detyped_request = described_class.new('/subsystem=jgroups/stack=tcpping:add(transport={type=TCP, transport=UDP, test=abc})').to_detyped_request
      expect(detyped_request).to eq(:operation => 'add', :address => [{ 'subsystem' => 'jgroups' }, { 'stack' => 'tcpping' }], 'transport' => { 'type' => 'TCP', 'transport' => 'UDP', 'test' => 'abc' })
    end

    it 'creates a request with a OBJECT parameteri alt syntax' do
      detyped_request = described_class.new('/subsystem=jgroups/stack=tcpping:add(transport={type=>TCP, transport=>UDP, test=>abc})').to_detyped_request
      expect(detyped_request).to eq(:operation => 'add', :address => [{ 'subsystem' => 'jgroups' }, { 'stack' => 'tcpping' }], 'transport' => { 'type' => 'TCP', 'transport' => 'UDP', 'test' => 'abc' })
    end

    it 'creates a request with a LIST parameter' do
      detyped_request = described_class.new('/subsystem=modcluster/mod-cluster-config=configuration:add(proxies=[host1, host2])').to_detyped_request
      expect(detyped_request).to eq(:operation => 'add', :address => [{ 'subsystem' => 'modcluster' }, { 'mod-cluster-config' => 'configuration' }], 'proxies' => %w(host1 host2))
    end

    it 'creates a request for a resource named with special character' do
      detyped_request = described_class.new('/subsystem=naming/binding="java:global/ldap/resource":add()').to_detyped_request
      expect(detyped_request).to eq(:operation => 'add', :address => [{ 'subsystem' => 'naming' }, { 'binding' => 'java:global/ldap/resource' }])
    end

    it 'creates a request for a complex operation with complex path' do
      detyped_request = described_class.new('/socket-binding-group=standard-sockets/remote-destinations-outbound-socket-binding=mail-smtp:add(host="www-smtp.localdomain", port=25)').to_detyped_request
      expect(detyped_request).to eq(:operation => 'add', :address => [{ 'socket-binding-group' => 'standard-sockets' }, { 'remote-destinations-outbound-socket-binding' => 'mail-smtp' }], 'host' => '"www-smtp.localdomain"', 'port' => '25')
    end
  end
end