/**
   * Starts Syslog server and configures syslog handler in the AS.
   *
   * @see
   *     org.jboss.as.arquillian.api.ServerSetupTask#setup(org.jboss.as.arquillian.container.ManagementClient,
   *     java.lang.String)
   */
  @Override
  public void setup(ManagementClient managementClient, String containerId) throws Exception {
    // clear created server instances (TCP/UDP)
    SyslogServer.shutdown();

    // start and set syslog server
    final String host = Utils.getHost(managementClient);
    SyslogServerConfigIF config = getSyslogConfig();
    config.setUseStructuredData(true);
    config.setHost(host);
    config.setPort(SYSLOG_PORT);
    config.addEventHandler(new BlockedSyslogServerEventHandler());
    final String syslogProtocol = getSyslogProtocol();
    server = SyslogServer.createInstance(syslogProtocol, config);
    // start syslog server
    SyslogServer.getThreadedInstance(syslogProtocol);

    ModelNode op;

    // set logging to syslog
    final ModelNode compositeOp = new ModelNode();
    compositeOp.get(OP).set(COMPOSITE);
    compositeOp.get(OP_ADDR).setEmptyList();
    ModelNode steps = compositeOp.get(STEPS);
    op = Util.createAddOperation(AUDIT_SYSLOG_HANDLER_ADDR);
    op.get(FORMATTER).set(JSON_FORMATTER);
    op.get(SYSLOG_FORMAT).set("RFC5424");
    steps.add(op);
    final ModelNode auditlogSyslogProtocol = addAuditlogSyslogProtocol();
    auditlogSyslogProtocol.get(PORT).set(SYSLOG_PORT);
    auditlogSyslogProtocol.get(HOST).set(host);
    steps.add(auditlogSyslogProtocol);
    Utils.applyUpdate(compositeOp, managementClient.getControllerClient());

    List<ModelNode> protocolSettings = addProtocolSettings();
    if (protocolSettings != null) {
      Utils.applyUpdates(protocolSettings, managementClient.getControllerClient());
    }

    op = Util.createAddOperation(AUDIT_LOG_LOGGER_SYSLOG_HANDLER_ADDR);
    Utils.applyUpdate(op, managementClient.getControllerClient());

    op = Util.getWriteAttributeOperation(AUDIT_LOG_LOGGER_ADDR, LOG_READ_ONLY, false);
    Utils.applyUpdate(op, managementClient.getControllerClient());
  }
  /**
   * Stops syslog server and removes auditlog configuration.
   *
   * @see
   *     org.jboss.as.arquillian.api.ServerSetupTask#tearDown(org.jboss.as.arquillian.container.ManagementClient,
   *     java.lang.String)
   */
  @Override
  public void tearDown(ManagementClient managementClient, String containerId) throws Exception {
    // stop syslog server
    SyslogServer.shutdown();
    server.setThread(null);
    server.getConfig().removeAllEventHandlers();

    ModelNode op = Util.createRemoveOperation(AUDIT_LOG_LOGGER_SYSLOG_HANDLER_ADDR);
    op.get(OPERATION_HEADERS, ROLLBACK_ON_RUNTIME_FAILURE).set(false);
    op.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
    Utils.applyUpdate(op, managementClient.getControllerClient());

    op = Util.createRemoveOperation(AUDIT_SYSLOG_HANDLER_ADDR);
    op.get(OPERATION_HEADERS, ROLLBACK_ON_RUNTIME_FAILURE).set(false);
    op.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
    Utils.applyUpdate(op, managementClient.getControllerClient());

    Utils.applyUpdate(
        Util.getWriteAttributeOperation(AUDIT_LOG_LOGGER_ADDR, LOG_READ_ONLY, false),
        managementClient.getControllerClient());
  }
  @After
  public void afterTest() throws Exception {
    // stop syslog server
    SyslogServer.shutdown();
    server.setThread(null);
    server.getConfig().removeAllEventHandlers();

    final ModelControllerClient client = TestSuiteEnvironment.getModelControllerClient();
    ModelNode op =
        Util.getWriteAttributeOperation(
            auditLogConfigAddress,
            AuditLogLoggerResourceDefinition.ENABLED.getName(),
            new ModelNode(false));
    client.execute(op);
    op =
        Util.getWriteAttributeOperation(
            mgmtRealmConfigAddress, "default-user", new ModelNode("$local"));
    client.execute(op);

    op = Util.getResourceRemoveOperation(addSyslogHandler);
    client.execute(op);
    op = Util.getResourceRemoveOperation(syslogHandlerAddress);
    client.execute(op);

    if (file.exists()) {
      file.delete();
    }
    if (syslogFile.exists()) {
      syslogFile.delete();
    }
    try {
      // Stop the container
      container.stop(CONTAINER);
    } finally {
      IoUtils.safeClose(client);
    }
  }