repo
stringlengths
1
191
file
stringlengths
23
351
code
stringlengths
0
5.32M
file_length
int64
0
5.32M
avg_line_length
float64
0
2.9k
max_line_length
int64
0
288k
extension_type
stringclasses
1 value
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jsf/version/ejb/JSFVersionEJB.java
/* * JBoss, Home of Professional Open Source * Copyright 2019, Red Hat, Inc. and/or its affiliates, and individual * contributors by the @authors tag. See the copyright.txt in the * distribution for a full listing of individual contributors. * * 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 org.jboss.as.test.integration.jsf.version.ejb; import jakarta.ejb.Stateless; import jakarta.faces.context.FacesContext; @Stateless public class JSFVersionEJB { public String getJSFVersion() { return "JSF VERSION: " + FacesContext.class.getPackage().getSpecificationTitle(); } }
1,103
37.068966
89
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jsf/version/war/JSFVersion.java
/* * JBoss, Home of Professional Open Source * Copyright 2019, Red Hat, Inc. and/or its affiliates, and individual * contributors by the @authors tag. See the copyright.txt in the * distribution for a full listing of individual contributors. * * 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 org.jboss.as.test.integration.jsf.version.war; import org.jboss.as.test.integration.jsf.version.ejb.JSFVersionEJB; import jakarta.ejb.EJB; import jakarta.enterprise.context.SessionScoped; import jakarta.inject.Named; import java.io.Serializable; @Named("jsfversion") @SessionScoped public class JSFVersion implements Serializable { /** Default value included to remove warning. **/ private static final long serialVersionUID = 1L; /** * Injected JSFVersionEJB client */ @EJB private JSFVersionEJB jsfVersionEJB; public String getJSFVersion() { return jsfVersionEJB.getJSFVersion(); } }
1,445
31.863636
75
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jsf/version/war/JSFMyFaces.java
/* * JBoss, Home of Professional Open Source * Copyright 2019, Red Hat, Inc. and/or its affiliates, and individual * contributors by the @authors tag. See the copyright.txt in the * distribution for a full listing of individual contributors. * * 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 org.jboss.as.test.integration.jsf.version.war; import jakarta.enterprise.context.SessionScoped; import jakarta.faces.annotation.FacesConfig; import jakarta.faces.context.FacesContext; import jakarta.inject.Named; import java.io.Serializable; @Named("jsfmyfacesversion") @SessionScoped @FacesConfig public class JSFMyFaces implements Serializable { /** Default value included to remove warning. **/ private static final long serialVersionUID = 1L; public String getJSFVersion() { return "MyFaces Bundled:" + FacesContext.class.getPackage().getSpecificationTitle(); } }
1,403
35.947368
92
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jsf/duplicateid/DuplicateIDIntegrationTestCase.java
package org.jboss.as.test.integration.jsf.duplicateid; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.LinkedList; import java.util.List; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.BasicResponseHandler; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.message.BasicNameValuePair; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ContainerResource; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.integration.jsf.duplicateid.deployment.IncludeBean; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Test case based on reproducer for https://issues.jboss.org/browse/JBEAP-10758 * <p> * Original reproducer: https://github.com/tuner/mojarra-dynamic-include-reproducer * Original reproducer author: Kari Lavikka <[email protected]> * * @author Jan Kasik <[email protected]> */ @RunWith(Arquillian.class) @RunAsClient public class DuplicateIDIntegrationTestCase { private static final Logger log = LoggerFactory.getLogger(DuplicateIDIntegrationTestCase.class); @ContainerResource private ManagementClient managementClient; private static final String HTTP = "http", APP_NAME = "duplicate-id-reproducer", WEB_XML = "web.xml", INDEX_XHTML = "index.xhtml", BUTTON_XHTML = "button.xhtml", COMP_XHTML = "comp.xhtml", FACES_CONFIG_XML = "faces-config.xml", COMPONENTS = "components", RESOURCES = "resources"; private static final int APPLICATION_PORT = 8080; @Deployment(testable = false, name = APP_NAME) public static Archive<?> deploy() { final String separator = "/", componentTargetPathPrefix = RESOURCES.concat(separator).concat(COMPONENTS).concat(separator); final Package resourcePackage = IncludeBean.class.getPackage(); WebArchive archive = ShrinkWrap.create(WebArchive.class, APP_NAME.concat(".war")) .addClass(IncludeBean.class) .addAsWebResource(resourcePackage, BUTTON_XHTML, componentTargetPathPrefix + BUTTON_XHTML) .addAsWebResource(resourcePackage, COMP_XHTML, componentTargetPathPrefix + COMP_XHTML) .addAsWebResource(resourcePackage, INDEX_XHTML) .addAsWebInfResource(resourcePackage, WEB_XML) .addAsWebInfResource(resourcePackage, FACES_CONFIG_XML); log.debug(archive.getContent().toString()); return archive; } /** * Verify, that loading two dynamically loaded elements won't cause a server error. * <ol> * <li>Send an initial request to obtain session id and view state.</li> * <li>Verify this request went OK.</li> * <li>Simulate clicking on a button labeled "Show 2" to "reveal" a text element which has assigned ID.</li> * <li>Verify that second request went OK too.</li> * <li>Simulate clicking on a button labeled "Show 3" to "reveal" a text element which has assigned ID. In state * when the bug is not fixed, new element receives same ID and response code is 500 - server error. Thus * verifying, that "clicking" went OK is crucial.</li> * <li>Also verify, that respond contains both displayed dynamic elements.</li> * </ol> */ @Test public void testDuplicateIDIsNotGenerated() throws IOException { final URL baseURL = new URL(HTTP, managementClient.getMgmtAddress(), APPLICATION_PORT, "/" + APP_NAME + "/" + IncludeBean.class.getPackage().getName().replaceAll("\\.", "/") + "/" + INDEX_XHTML); try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) { log.debug("Sending initial request to '{}'.", baseURL.toString()); final HttpResponse initialResponse = httpClient.execute(new HttpPost(baseURL.toString())); assertEquals(HttpURLConnection.HTTP_OK, initialResponse.getStatusLine().getStatusCode()); final Form initialResponseForm = new Form(initialResponse); final HttpResponse afterFirstClickResponse = simulateClickingOnButton(httpClient, initialResponseForm, "Show 3"); assertEquals(HttpURLConnection.HTTP_OK, afterFirstClickResponse.getStatusLine().getStatusCode()); final Form formAfterFirstClick = new Form(afterFirstClickResponse); final HttpResponse afterSecondClickResponse = simulateClickingOnButton(httpClient, formAfterFirstClick, "Show 2"); assertEquals(HttpURLConnection.HTTP_OK, afterSecondClickResponse.getStatusLine().getStatusCode()); final String responseString = new BasicResponseHandler().handleResponse(afterSecondClickResponse); assertTrue("There should be text which appears after clicking on second button in response!", responseString.contains(">OutputText 2</span>")); assertTrue("There should be text which appears after clicking on first button in response!", responseString.contains(">OutputText 3</span>")); } } private HttpResponse simulateClickingOnButton(HttpClient client, Form form, String buttonValue) throws IOException { final URL url = new URL(HTTP, managementClient.getMgmtAddress(), APPLICATION_PORT, form.getAction()); final HttpPost request = new HttpPost(url.toString()); final List<NameValuePair> params = new LinkedList<>(); for (Input input : form.getInputFields()) { if (input.type == Input.Type.HIDDEN || (input.type == Input.Type.SUBMIT && input.getValue().equals(buttonValue))) { params.add(new BasicNameValuePair(input.getName(), input.getValue())); } } request.setEntity(new UrlEncodedFormEntity(params, StandardCharsets.UTF_8)); log.debug("Clicking on submit button '{}'.", buttonValue); return client.execute(request); } private final class Form { static final String NAME = "name", VALUE = "value", INPUT = "input", TYPE = "type", ACTION = "action", FORM = "form"; final HttpResponse response; final String action; final List<Input> inputFields = new LinkedList<>(); public Form(HttpResponse response) throws IOException { this.response = response; log.debug(response.getStatusLine().toString()); final String responseString = new BasicResponseHandler().handleResponse(response); final Document doc = Jsoup.parse(responseString); final Element form = doc.select(FORM).first(); this.action = form.attr(ACTION); for (Element input : form.select(INPUT)) { Input.Type type = null; switch (input.attr(TYPE)) { case "submit": type = Input.Type.SUBMIT; break; case "hidden": type = Input.Type.HIDDEN; break; } inputFields.add(new Input(input.attr(NAME), input.attr(VALUE), type)); } } public String getAction() { return action; } public List<Input> getInputFields() { return inputFields; } } private static final class Input { final String name, value; final Type type; public Input(String name, String value, Type type) { this.name = name; this.value = value; this.type = type; } public String getName() { return name; } public String getValue() { return value; } public enum Type { HIDDEN, SUBMIT } } }
8,806
41.341346
126
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jsf/duplicateid/deployment/IncludeBean.java
package org.jboss.as.test.integration.jsf.duplicateid.deployment; import jakarta.faces.annotation.FacesConfig; import jakarta.faces.view.ViewScoped; import jakarta.inject.Named; import java.io.Serializable; import java.util.HashSet; import java.util.Set; /** * @author Kari */ @Named("includeBean") @ViewScoped // TODO remove once standard WildFly moves to Faces 4 @FacesConfig public class IncludeBean implements Serializable { private final Set<Integer> visibleComponentIndexes = new HashSet<Integer>(); public void show(int index) { visibleComponentIndexes.add(index); } public void hide(int index) { visibleComponentIndexes.remove(index); } public boolean isVisible(int index) { return visibleComponentIndexes.contains(index); } }
794
23.84375
80
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jsf/flash/FlashScopeDistributedSessionTestCase.java
package org.jboss.as.test.integration.jsf.flash; import java.net.URL; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(Arquillian.class) @RunAsClient public class FlashScopeDistributedSessionTestCase { @ArquillianResource URL url; @Deployment public static Archive<?> deploy() { final WebArchive war = ShrinkWrap.create(WebArchive.class, "jsfflashscope.war"); Package pakkage = FlashScopeDistributedSessionTestCase.class.getPackage(); war.addAsWebInfResource(pakkage, "web.xml", "web.xml"); war.addAsWebInfResource(pakkage, "faces-config.xml", "faces-config.xml"); war.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); war.addAsWebResource(pakkage, "getvar.xhtml", "getvar.xhtml"); war.addAsWebResource(pakkage, "getvar2.xhtml", "getvar2.xhtml"); war.addAsWebResource(pakkage, "setvar.xhtml", "setvar.xhtml"); war.addAsWebResource(pakkage, "setvar2.xhtml", "setvar2.xhtml"); return war; } @Test public void testSettingAndReadingFlashVar() throws Exception { HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); try (CloseableHttpClient client = httpClientBuilder.build()) { HttpUriRequest setVarRequest = new HttpGet(url.toExternalForm() + "setvar.jsf"); HttpUriRequest getVarRequest = new HttpGet(url.toExternalForm() + "getvar.jsf"); client.execute(setVarRequest).close(); try (CloseableHttpResponse getVarResponse = client.execute(getVarRequest)) { String text = EntityUtils.toString(getVarResponse.getEntity()); Assert.assertTrue("Text should contain \"Flash Variable: hello\", but is [" + text + "]", text.contains("Flash Variable: hello")); } } } @Test public void testReadingEmptyFlashVar() throws Exception { HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); try (CloseableHttpClient client = httpClientBuilder.build()) { HttpUriRequest getVarRequest = new HttpGet(url.toExternalForm() + "getvar2.jsf"); try (CloseableHttpResponse getVarResponse = client.execute(getVarRequest)) { String text = EntityUtils.toString(getVarResponse.getEntity()); Assert.assertTrue("Text should contain \"Flash Variable: null\", but is [" + text + "]", text.contains("Flash Variable: null")); } } } @Test public void testPuttingFlashVarOnNonTransientPage() throws Exception { HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); try (CloseableHttpClient client = httpClientBuilder.build()) { HttpUriRequest setVarRequest = new HttpGet(url.toExternalForm() + "setvar2.jsf"); try (CloseableHttpResponse setVarResponse = client.execute(setVarRequest)) { String text = EntityUtils.toString(setVarResponse.getEntity()); Assert.assertEquals("Put operation failedwith: " + text, 200, setVarResponse.getStatusLine().getStatusCode()); } } } }
3,877
44.623529
146
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/JcaTestsUtil.java
/* * * * JBoss, Home of Professional Open Source. * * Copyright 2015, Red Hat, Inc., and individual contributors * * as indicated by the @author tags. See the copyright.txt file in the * * distribution for a full listing of individual contributors. * * * * This is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as * * published by the Free Software Foundation; either version 2.1 of * * the License, or (at your option) any later version. * * * * This software is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this software; if not, write to the Free * * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * * 02110-1301 USA, or see the FSF site: http://www.fsf.org. * */ package org.jboss.as.test.integration.jca; import static org.junit.Assert.fail; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.concurrent.ConcurrentMap; import org.jboss.as.connector.services.workmanager.StatisticsExecutorImpl; import org.jboss.as.connector.subsystems.datasources.WildFlyDataSource; import org.jboss.jca.adapters.jdbc.WrapperDataSource; import org.jboss.jca.core.api.connectionmanager.pool.PoolConfiguration; import org.jboss.jca.core.connectionmanager.ConnectionManager; import org.jboss.jca.core.connectionmanager.pool.api.Pool; import org.jboss.jca.core.connectionmanager.pool.mcp.ManagedConnectionPool; import org.jboss.jca.core.util.Injection; import org.jboss.threads.BlockingExecutor; /** * Utility class for Jakarta Connectors integration test * * @author <a href="mailto:[email protected]">Martin Simka</a> */ public class JcaTestsUtil { /** * set lastIdleCheck property in ManagedConnectionPool to minimun and ManagedConnectionPool's removeIdleConnection * * @param mcp * @throws Exception */ public static void callRemoveIdleConnections(ManagedConnectionPool mcp) throws Exception { Injection in = new Injection(); in.inject(mcp, "lastIdleCheck", Long.MIN_VALUE, long.class.getName(), true); mcp.removeIdleConnections(); } /** * Extract ManagedConnectionPool from ConnectionFactory by using reflection * * @param connectionFactory * @return ManagedConnectionPool instance. <code>null</code> if not found */ public static ManagedConnectionPool extractManagedConnectionPool(Object connectionFactory) { ConnectionManager cm = extractConnectionManager(connectionFactory); // org.jboss.jca.core.connectionmanager.pool.strategy.OnePool Object onePool = cm.getPool(); Class<?> clz = onePool.getClass(); // org.jboss.jca.core.connectionmanager.pool.AbstractPrefillPool clz = clz.getSuperclass(); // org.jboss.jca.core.connectionmanager.pool.AbstractPool clz = clz.getSuperclass(); try { Method getManagedConnectionPools = clz.getDeclaredMethod("getManagedConnectionPools"); getManagedConnectionPools.setAccessible(true); ConcurrentMap<Object, ManagedConnectionPool> mcps = (ConcurrentMap<Object, ManagedConnectionPool>) getManagedConnectionPools.invoke(onePool); return mcps.values().iterator().next(); } catch (Throwable t) { fail(t.getMessage()); } return null; } public static PoolConfiguration exctractPoolConfiguration(Object connectionFactory) { ConnectionManager cm = extractConnectionManager(connectionFactory); // org.jboss.jca.core.connectionmanager.pool.strategy.OnePool Pool pool = cm.getPool(); Class<?> clz = pool.getClass(); // org.jboss.jca.core.connectionmanager.pool.AbstractPrefillPool clz = clz.getSuperclass(); // org.jboss.jca.core.connectionmanager.pool.AbstractPool clz = clz.getSuperclass(); try { Method getPoolConfiguration = clz.getDeclaredMethod("getPoolConfiguration"); getPoolConfiguration.setAccessible(true); return (PoolConfiguration) getPoolConfiguration.invoke(pool); } catch (Throwable t) { fail(t.getMessage()); } return null; } public static PoolConfiguration extractDSPoolConfiguration(Object datasource) { try { Field delegateField = datasource.getClass().getDeclaredField("delegate"); Object delegate = delegateField.get(datasource); } catch (Throwable t) { fail(t.getMessage()); } return null; } /** * Extract ConnectionManager from the passed object * * @param connectionFactory The object; typically a ConnectionFactory implementation * @return The connection manager; <code>null</code> if not found */ private static ConnectionManager extractConnectionManager(Object connectionFactory) { Class<?> clz = connectionFactory.getClass(); while (!Object.class.equals(clz)) { try { Field[] fields = clz.getDeclaredFields(); if (fields != null && fields.length > 0) { for (Field field : fields) { Class<?> fieldType = field.getType(); if (fieldType.equals(jakarta.resource.spi.ConnectionManager.class) || fieldType.equals(ConnectionManager.class)) { field.setAccessible(true); return (ConnectionManager) field.get(connectionFactory); } } } } catch (Throwable t) { fail(t.getMessage()); } try { Method[] methods = clz.getDeclaredMethods(); for (Method method : methods) { Class<?> type = method.getReturnType(); if (type.equals(jakarta.resource.spi.ConnectionManager.class) || type.equals(ConnectionManager.class)) { method.setAccessible(true); return (ConnectionManager) method.invoke(connectionFactory); } } } catch (Throwable t) { fail(t.getMessage()); } clz = clz.getSuperclass(); } return null; } /** * Extract WrapperDataSource from WildflyDataSource by using reflection * * @param wfds * @return WrapperDataSource instance, <code>null</code> if not found */ public static WrapperDataSource extractWrapperDatasource(WildFlyDataSource wfds) { Class clazz = wfds.getClass(); try { Field delegate = clazz.getDeclaredField("delegate"); delegate.setAccessible(true); return (WrapperDataSource) delegate.get(wfds); } catch (Throwable t) { fail(t.getMessage()); } return null; } /** * Extract BlockingExecutor from StatisticsExecutorImpl by using reflection * * @param sei * @return BlockingExecutor instance, <code>null</code> if not found */ public static BlockingExecutor extractBlockingExecutor(StatisticsExecutorImpl sei) { Class clazz = sei.getClass(); try { Field delegate = clazz.getDeclaredField("realExecutor"); delegate.setAccessible(true); return (BlockingExecutor) delegate.get(sei); } catch (Throwable t) { fail(t.getMessage()); } return null; } }
7,911
38.168317
153
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/JcaMgmtBase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION; import org.jboss.as.test.integration.management.base.ContainerResourceMgmtTestBase; import org.jboss.as.test.shared.ServerReload; import org.jboss.dmr.ModelNode; /** * Base class for JCA related tests * * @author <a href="mailto:[email protected]">Vladimir Rastseluev</a> */ public class JcaMgmtBase extends ContainerResourceMgmtTestBase { protected static ModelNode subsystemAddress = new ModelNode().add(SUBSYSTEM, "jca"); protected static ModelNode archiveValidationAddress = subsystemAddress.clone().add("archive-validation", "archive-validation"); /** * Provide reload operation on server * * @throws Exception */ public void reload() throws Exception { ServerReload.executeReloadAndWaitForCompletion(getManagementClient(), 50000); } /** * Reads attribute from DMR model * * @param address to read * @param attributeName * @return attribute value * @throws Exception */ public ModelNode readAttribute(ModelNode address, String attributeName) throws Exception { ModelNode op = new ModelNode(); op.get(OP).set(READ_ATTRIBUTE_OPERATION); op.get(NAME).set(attributeName); op.get(OP_ADDR).set(address); return executeOperation(op); } /** * Writes attribute value * * @param address to write * @param attributeName * @param attributeValue * @return result of operation * @throws Exception */ public ModelNode writeAttribute(ModelNode address, String attributeName, String attributeValue) throws Exception { ModelNode op = new ModelNode(); op.get(OP).set(WRITE_ATTRIBUTE_OPERATION); op.get(NAME).set(attributeName); op.get(VALUE).set(attributeValue); op.get(OP_ADDR).set(address); return executeOperation(op); } /** * Set parameters for archive validation in JCA * * @param enabled - if validation is enabled * @param failOnErr - if validation should fail an error * @param failOnWarn - if validation should fail on error or warning * @throws Exception */ public void setArchiveValidation(boolean enabled, boolean failOnErr, boolean failOnWarn) throws Exception { remove(archiveValidationAddress); ModelNode op = new ModelNode(); op.get(OP).set(ADD); op.get(OP_ADDR).set(archiveValidationAddress); op.get("enabled").set(enabled); op.get("fail-on-error").set(failOnErr); op.get("fail-on-warn").set(failOnWarn); executeOperation(op); reload(); } /** * Get some attribute from archive validation settings of server * * @param attributeName * @return boolean value of attribute * @throws Exception */ public boolean getArchiveValidationAttribute(String attributeName) throws Exception { return readAttribute(archiveValidationAddress, attributeName).asBoolean(); } /** * Executes operation operationName on node * * @param node * @param operationName * @return result of execution * @throws Exception */ protected ModelNode executeOnNode(ModelNode node, String operationName) throws Exception { ModelNode operation = new ModelNode(); operation.get(OP).set(operationName); operation.get(OP_ADDR).set(node); return executeOperation(operation); } /** * Returns int value of statistics attribute * * @param attributeName * @param statisticNode - address of statistics node * @return int value of attribute * @throws Exception */ protected int getStatisticsAttribute(String attributeName, ModelNode statisticNode) throws Exception { return readAttribute(statisticNode, attributeName).asInt(); } }
5,639
35.862745
131
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/JcaMgmtServerSetupTask.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca; import org.jboss.as.arquillian.api.ServerSetupTask; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.shared.ServerSnapshot; /** * Implementation of ServerSetupTask for JCA related tests * * @author <a href="mailto:[email protected]">Vladimir Rastseluev</a> */ public abstract class JcaMgmtServerSetupTask extends JcaMgmtBase implements ServerSetupTask { private AutoCloseable snapshot; @Override public final void setup(final ManagementClient managementClient, final String containerId) throws Exception { snapshot = ServerSnapshot.takeSnapshot(managementClient); setManagementClient(managementClient); doSetup(managementClient); } protected abstract void doSetup(final ManagementClient managementClient) throws Exception; @Override public final void tearDown(ManagementClient managementClient, String containerId) throws Exception { snapshot.close(); } }
2,033
38.882353
113
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/DataSourceClassInfoTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2018, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca; import static org.jboss.as.controller.client.helpers.ClientConstants.INCLUDE_RUNTIME; import static org.jboss.as.controller.client.helpers.ClientConstants.OP; import static org.jboss.as.controller.client.helpers.ClientConstants.OP_ADDR; import static org.jboss.as.controller.client.helpers.ClientConstants.READ_ATTRIBUTE_OPERATION; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.controller.client.helpers.Operations; import org.jboss.as.test.integration.management.base.ContainerResourceMgmtTestBase; import org.jboss.dmr.ModelNode; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * @author <a href="mailto:[email protected]">Lin Gao</a> */ @RunWith(Arquillian.class) @RunAsClient public class DataSourceClassInfoTestCase extends ContainerResourceMgmtTestBase { private ModelNode getDsClsInfoOperation(String driverName) { ModelNode driverAddress = new ModelNode(); driverAddress.add("subsystem", "datasources"); driverAddress.add("jdbc-driver", driverName); ModelNode op = Operations.createReadResourceOperation(driverAddress); op.get(INCLUDE_RUNTIME).set(true); return op; } @Test public void testGetDsClsInfo() throws Exception { ModelNode operation = getDsClsInfoOperation("h2"); ModelNode result = getManagementClient().getControllerClient().execute(operation); Assert.assertNotNull(result); Assert.assertEquals("success", result.get("outcome").asString()); ModelNode dsInfoList = result.get("result").get("datasource-class-info"); Assert.assertNotNull(dsInfoList); ModelNode dsInfo = dsInfoList.get(0).get("org.h2.jdbcx.JdbcDataSource"); Assert.assertNotNull(dsInfo); Assert.assertEquals("java.lang.String", dsInfo.get("description").asString()); Assert.assertEquals("java.lang.String", dsInfo.get("user").asString()); Assert.assertEquals("java.lang.String", dsInfo.get("url").asString()); Assert.assertEquals("java.lang.String", dsInfo.get("password").asString()); Assert.assertEquals("int", dsInfo.get("loginTimeout").asString()); } @Test public void testGetDsClsInfoByReadAttribute() throws Exception { ModelNode driverAddress = new ModelNode(); driverAddress.add("subsystem", "datasources"); driverAddress.add("jdbc-driver", "h2"); ModelNode op = new ModelNode(); op.get(OP_ADDR).set(driverAddress); op.get(OP).set(READ_ATTRIBUTE_OPERATION); op.get("name").set("datasource-class-info"); ModelNode result = getManagementClient().getControllerClient().execute(op); Assert.assertNotNull(result); Assert.assertEquals("success", result.get("outcome").asString()); ModelNode dsInfoList = result.get("result"); Assert.assertNotNull(dsInfoList); ModelNode dsInfo = dsInfoList.get(0).get("org.h2.jdbcx.JdbcDataSource"); Assert.assertNotNull(dsInfo); Assert.assertEquals("java.lang.String", dsInfo.get("description").asString()); Assert.assertEquals("java.lang.String", dsInfo.get("user").asString()); Assert.assertEquals("java.lang.String", dsInfo.get("url").asString()); Assert.assertEquals("java.lang.String", dsInfo.get("password").asString()); Assert.assertEquals("int", dsInfo.get("loginTimeout").asString()); } @Test public void testInstalledDriverList() throws Exception { // installed-drivers-list ModelNode subsysAddr = new ModelNode(); subsysAddr.add("subsystem", "datasources"); ModelNode op = new ModelNode(); op.get(OP_ADDR).set(subsysAddr); op.get(OP).set("installed-drivers-list"); ModelNode result = getManagementClient().getControllerClient().execute(op); Assert.assertNotNull(result); Assert.assertEquals("success", result.get("outcome").asString()); ModelNode dsInfoList = result.get("result"); Assert.assertNotNull(dsInfoList); Assert.assertTrue(dsInfoList.get(0).has("driver-datasource-class-name")); ModelNode dsInfo = dsInfoList.get(0).get("datasource-class-info").get(0).get("org.h2.jdbcx.JdbcDataSource"); Assert.assertNotNull(dsInfo); Assert.assertEquals("java.lang.String", dsInfo.get("description").asString()); Assert.assertEquals("java.lang.String", dsInfo.get("user").asString()); Assert.assertEquals("java.lang.String", dsInfo.get("url").asString()); Assert.assertEquals("java.lang.String", dsInfo.get("password").asString()); Assert.assertEquals("int", dsInfo.get("loginTimeout").asString()); } @Test public void testGetInstalledDriver() throws Exception { // get-installed-driver(driver-name=h2) ModelNode subsysAddr = new ModelNode(); subsysAddr.add("subsystem", "datasources"); ModelNode op = new ModelNode(); op.get(OP_ADDR).set(subsysAddr); op.get(OP).set("get-installed-driver"); op.get("driver-name").set("h2"); ModelNode result = getManagementClient().getControllerClient().execute(op); Assert.assertNotNull(result); Assert.assertEquals("success", result.get("outcome").asString()); ModelNode dsInfoList = result.get("result"); Assert.assertNotNull(dsInfoList); Assert.assertTrue(dsInfoList.get(0).has("driver-datasource-class-name")); ModelNode dsInfo = dsInfoList.get(0).get("datasource-class-info").get(0).get("org.h2.jdbcx.JdbcDataSource"); Assert.assertNotNull(dsInfo); Assert.assertEquals("java.lang.String", dsInfo.get("description").asString()); Assert.assertEquals("java.lang.String", dsInfo.get("user").asString()); Assert.assertEquals("java.lang.String", dsInfo.get("url").asString()); Assert.assertEquals("java.lang.String", dsInfo.get("password").asString()); Assert.assertEquals("int", dsInfo.get("loginTimeout").asString()); } }
7,162
45.212903
116
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/anno/RaAnnoTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.anno; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.Iterator; import java.util.List; import java.util.Set; import org.jboss.logging.Logger; import jakarta.annotation.Resource; import jakarta.resource.spi.ActivationSpec; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.connector.subsystems.resourceadapters.Namespace; import org.jboss.as.connector.subsystems.resourceadapters.ResourceAdapterSubsystemParser; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.test.integration.jca.annorar.AnnoActivationSpec; import org.jboss.as.test.integration.jca.annorar.AnnoAdminObject; import org.jboss.as.test.integration.jca.annorar.AnnoConnectionFactory; import org.jboss.as.test.integration.jca.annorar.AnnoConnectionImpl; import org.jboss.as.test.integration.jca.annorar.AnnoManagedConnectionFactory; import org.jboss.as.test.integration.jca.annorar.AnnoMessageListener; import org.jboss.as.test.integration.jca.annorar.AnnoMessageListener1; import org.jboss.as.test.integration.jca.annorar.AnnoResourceAdapter; import org.jboss.as.test.integration.management.base.AbstractMgmtServerSetupTask; import org.jboss.as.test.integration.management.base.AbstractMgmtTestBase; import org.jboss.as.test.shared.FileUtils; import org.jboss.dmr.ModelNode; import org.jboss.jca.common.metadata.spec.ConnectorImpl; import org.jboss.jca.core.spi.mdr.MetadataRepository; import org.jboss.jca.core.spi.rar.Endpoint; import org.jboss.jca.core.spi.rar.MessageListener; import org.jboss.jca.core.spi.rar.ResourceAdapterRepository; import org.jboss.msc.service.ServiceContainer; import org.jboss.msc.service.ServiceController; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * Activation of annotated RA, overridden by descriptor * * @author <a href="mailto:[email protected]">Vladimir Rastseluev</a> */ @RunWith(Arquillian.class) @ServerSetup(RaAnnoTestCase.NoRaAnnoTestCaseSetup.class) public class RaAnnoTestCase { /** * The logger */ private static Logger log = Logger.getLogger("RaAnnoTestCase"); static class NoRaAnnoTestCaseSetup extends AbstractMgmtServerSetupTask { private ModelNode address; @Override public void doSetup(final ManagementClient managementClient) throws Exception { String xml = FileUtils.readFile(RaAnnoTestCase.class, "ra16anno.xml"); List<ModelNode> operations = xmlToModelOperations(xml, Namespace.RESOURCEADAPTERS_1_0.getUriString(), new ResourceAdapterSubsystemParser()); address = operations.get(1).get("address"); executeOperation(operationListToCompositeOperation(operations)); } @Override public void tearDown(final ManagementClient managementClient, final String containerId) throws Exception { remove(address); } } /** * Define the deployment * * @return The deployment archive * @throws Exception in case of error */ @Deployment public static ResourceAdapterArchive createDeployment() throws Exception { ResourceAdapterArchive raa = ShrinkWrap.create( ResourceAdapterArchive.class, "ra16anno.rar"); JavaArchive ja = ShrinkWrap.create(JavaArchive.class); ja.addClasses(RaAnnoTestCase.class); ja.addPackage(AbstractMgmtTestBase.class.getPackage()).addPackage( AnnoConnectionFactory.class.getPackage()); raa.addAsLibrary(ja) .addAsManifestResource(RaAnnoTestCase.class.getPackage(), "ra.xml", "ra.xml") .addAsManifestResource( new StringAsset( "Dependencies: javax.inject.api,org.jboss.as.connector\n"), "MANIFEST.MF"); return raa; } /** * Resource */ @Resource(mappedName = "java:/eis/ra16anno") private AnnoConnectionFactory connectionFactory1; /** * Resource */ @Resource(mappedName = "java:/eis/ao/ra16anno") private AnnoAdminObject adminObject; @ArquillianResource ServiceContainer serviceContainer; /** * Test getConnection * * @throws Throwable Thrown if case of an error */ @Test public void testGetConnection1() throws Throwable { assertNotNull(connectionFactory1); AnnoConnectionImpl connection1 = (AnnoConnectionImpl) connectionFactory1 .getConnection(); assertNotNull(connection1); AnnoManagedConnectionFactory mcf = connection1.getMCF(); assertNotNull(mcf); log.trace("MCF:" + mcf + "//1//" + mcf.getFirst() + "//2//" + mcf.getSecond()); assertEquals((byte) 23, (byte) mcf.getFirst()); assertEquals((short) 55, (short) mcf.getSecond()); connection1.close(); } /** * Test admin objects * * @throws Throwable Thrown if case of an error */ @Test public void testAdminOjbect() throws Throwable { assertNotNull(adminObject); log.trace("AO:" + adminObject + "//1//" + adminObject.getFirst() + "//2//" + adminObject.getSecond()); assertEquals((long) 54321, (long) adminObject.getFirst()); assertEquals(true, adminObject.getSecond()); } /** * test activation 1 * * @throws Throwable Thrown if case of an error */ @Test public void testActivation1() throws Throwable { testActivation(AnnoMessageListener.class); } /** * test activation 2 * * @throws Throwable Thrown if case of an error */ //@Test public void testActivation2() throws Throwable { testActivation(AnnoMessageListener1.class); } /** * Test activation * * @param clazz class name * @throws Throwable Thrown if case of an error */ public void testActivation(Class clazz) throws Throwable { ServiceController<?> controller = serviceContainer .getService(ConnectorServices.RA_REPOSITORY_SERVICE); assertNotNull(controller); ResourceAdapterRepository raRepository = (ResourceAdapterRepository) controller .getValue(); Set<String> ids = raRepository.getResourceAdapters(clazz); assertNotNull(ids); assertEquals(1, ids.size()); String piId = ids.iterator().next(); assertNotNull(piId); Endpoint endpoint = raRepository.getEndpoint(piId); assertNotNull(endpoint); List<MessageListener> listeners = raRepository .getMessageListeners(piId); assertNotNull(listeners); assertEquals(1, listeners.size()); MessageListener listener = listeners.get(0); ActivationSpec as = listener.getActivation().createInstance(); assertNotNull(as); assertNotNull(as.getResourceAdapter()); AnnoActivationSpec tas = (AnnoActivationSpec) as; log.trace("AS:" + tas + "//1//" + tas.getFirst() + "//2//" + tas.getSecond()); assertEquals(new Character('U'), tas.getFirst()); assertEquals(new Double(4.4), tas.getSecond()); assertTrue(tas.getResourceAdapter() instanceof AnnoResourceAdapter); AnnoResourceAdapter tra = (AnnoResourceAdapter) tas .getResourceAdapter(); log.trace("RA:" + tra + "//1//" + tra.getFirst() + "//2//" + tra.getSecond()); assertEquals("G", tra.getFirst()); assertEquals(new Integer(99), tra.getSecond()); } /** * Test metadata * * @throws Throwable Thrown if case of an error */ @Test public void testMetaData() throws Throwable { ServiceController<?> controller = serviceContainer .getService(ConnectorServices.IRONJACAMAR_MDR); assertNotNull(controller); MetadataRepository mdr = (MetadataRepository) controller.getValue(); assertNotNull(mdr); Set<String> ids = mdr.getResourceAdapters(); assertNotNull(ids); assertTrue(ids.size() > 0); String piId = getElementContaining(ids, "ra16anno"); assertNotNull(mdr.getResourceAdapter(piId)); assertTrue(mdr.getResourceAdapter(piId) instanceof ConnectorImpl); } /** * Checks Set if there is a String element, containing some substring and * returns it * * @param ids - Set * @param contain - substring * @return String */ public String getElementContaining(Set<String> ids, String contain) { Iterator<String> it = ids.iterator(); while (it.hasNext()) { String t = it.next(); if (t.contains(contain)) { return t; } } return null; } }
10,488
35.420139
93
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/anno/RaAnnoEmptyRaXmlFromModuleTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2023, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.anno; import jakarta.annotation.Resource; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.client.ModelControllerClient; import org.jboss.as.test.integration.jca.annorar.AnnoAdminObject; import org.jboss.as.test.integration.jca.annorar.AnnoConnectionFactory; import org.jboss.as.test.integration.jca.annorar.AnnoConnectionImpl; import org.jboss.as.test.integration.jca.annorar.AnnoManagedConnectionFactory; import org.jboss.as.test.integration.jca.moduledeployment.AbstractModuleDeploymentTestCaseSetup; import org.jboss.as.test.integration.management.ManagementOperations; import org.jboss.as.test.module.util.TestModule; import org.jboss.as.test.shared.ServerReload; import org.jboss.as.test.shared.SnapshotRestoreSetupTask; import org.jboss.dmr.ModelNode; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Test; import org.junit.runner.RunWith; import java.io.ByteArrayInputStream; import java.io.File; import java.io.InputStream; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; import static org.jboss.as.controller.client.helpers.ClientConstants.ADD; import static org.jboss.as.controller.client.helpers.ClientConstants.OP; import static org.jboss.as.controller.client.helpers.ClientConstants.OP_ADDR; import static org.jboss.as.controller.client.helpers.ClientConstants.SUBSYSTEM; import static org.jboss.as.controller.client.helpers.ClientConstants.VALUE; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; /** * Annotated RA with empty ra.xml and deployed as JBoss module. * * @author <a href="mailto:[email protected]">Lin Gao</a> */ @RunWith(Arquillian.class) @ServerSetup(RaAnnoEmptyRaXmlFromModuleTestCase.EmptyRaXMLWithAnnotationSetup.class) public class RaAnnoEmptyRaXmlFromModuleTestCase { private static final String MODULE_NAME = "org.jboss.ironjacamar.ra16out"; private static final String JNDI_CF = "java:/eis/raannocf"; private static final String JNDI_AO = "java:/eis/ao/ra16annoao"; private static final String RA_MODULE = "ramodule"; private static final String CF_POOL = "ConnectionPool"; private static final String AO_POOL = "AdminObjectPool"; private static final PathAddress RA_ADDRESS = PathAddress.pathAddress(SUBSYSTEM, "resource-adapters") .append("resource-adapter", RA_MODULE); private static final String RA_EMPTY = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<connector xmlns=\"http://java.sun.com/xml/ns/javaee\"\n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee\n" + " http://java.sun.com/xml/ns/j2ee/connector_1_6.xsd\"\n" + " version=\"1.6\" metadata-complete=\"false\">\n" + "\n" + " <vendor-name>Red Hat Middleware LLC</vendor-name>\n" + " <eis-type>Test RA</eis-type>\n" + " <resourceadapter-version>0.1</resourceadapter-version>\n" + " <resourceadapter />\n" + "</connector>"; public static class EmptyRaXMLWithAnnotationSetup extends SnapshotRestoreSetupTask { private TestModule customModule; private Path metaPath; @Override public void doSetup(ManagementClient managementClient, String s) throws Exception { // create the ra module ClassLoader cl = RaAnnoEmptyRaXmlFromModuleTestCase.class.getClassLoader(); URL moduleURL = cl.getResource(RaAnnoEmptyRaXmlFromModuleTestCase.class.getPackageName().replace(".", File.separator) + "/ramodule.xml"); assertNotNull(moduleURL); customModule = new TestModule(MODULE_NAME, new File(moduleURL.toURI())); customModule.addResource("ra16out.jar").addPackage(AnnoConnectionFactory.class.getPackage()); customModule.create(); // create META-INF/ra.xml to the ra module try (InputStream input = new ByteArrayInputStream(RA_EMPTY.getBytes())) { metaPath = TestModule.getModulesDirectory(false) .toPath() .resolve(MODULE_NAME.replace('.', File.separatorChar)) .resolve("main") .resolve("META-INF"); if (Files.notExists(metaPath)) { Files.createDirectories(metaPath); } Files.copy(input, metaPath.resolve("ra.xml"), StandardCopyOption.REPLACE_EXISTING); } // create activation in ra subsystem createRAActivation(managementClient.getControllerClient()); ServerReload.executeReloadAndWaitForCompletion(managementClient, 50000); } private void createRAActivation(ModelControllerClient modelControllerClient) throws Exception { final ModelNode createRAOp = new ModelNode(); createRAOp.get(OP).set(ADD); createRAOp.get(OP_ADDR).set(RA_ADDRESS.toModelNode()); createRAOp.get("module").set(MODULE_NAME); createRAOp.get("transaction-support").set("NoTransaction"); ManagementOperations.executeOperation(modelControllerClient, createRAOp); ModelNode createCDOp = new ModelNode(); createCDOp.get(OP).set(ADD); createCDOp.get(OP_ADDR).set(RA_ADDRESS.append("connection-definitions", CF_POOL).toModelNode()); createCDOp.get("class-name").set("org.jboss.as.test.integration.jca.annorar.AnnoManagedConnectionFactory"); createCDOp.get("jndi-name").set(JNDI_CF); ManagementOperations.executeOperation(modelControllerClient, createCDOp); ModelNode createAOOp = new ModelNode(); createAOOp.get(OP).set(ADD); createAOOp.get(OP_ADDR).set(RA_ADDRESS.append("admin-objects", AO_POOL).toModelNode()); createAOOp.get("jndi-name").set(JNDI_AO); createAOOp.get("class-name").set("org.jboss.as.test.integration.jca.annorar.AnnoAdminObjectImpl"); ManagementOperations.executeOperation(modelControllerClient, createAOOp); ModelNode cpFirstOp = new ModelNode(); cpFirstOp.get(OP).set(ADD); cpFirstOp.get(OP_ADDR).set(RA_ADDRESS.append("connection-definitions", CF_POOL).append("config-properties", "first").toModelNode()); cpFirstOp.get(VALUE).set(23); ManagementOperations.executeOperation(modelControllerClient, cpFirstOp); ModelNode aoSecondOp = new ModelNode(); aoSecondOp.get(OP).set(ADD); aoSecondOp.get(OP_ADDR).set(RA_ADDRESS.append("admin-objects", AO_POOL).append("config-properties", "second").toModelNode()); aoSecondOp.get(VALUE).set(true); ManagementOperations.executeOperation(modelControllerClient, aoSecondOp); // activate ModelNode raActivateOp = new ModelNode(); raActivateOp.get(OP).set("activate"); raActivateOp.get(OP_ADDR).set(RA_ADDRESS.toModelNode()); ManagementOperations.executeOperation(modelControllerClient, raActivateOp); } @Override public void nonManagementCleanUp() throws Exception { // delete meta directory if (metaPath != null) { Files.deleteIfExists(metaPath); } // delete module if (customModule != null) { customModule.remove(); } } } @Deployment public static JavaArchive createDeployment() { return ShrinkWrap.create(JavaArchive.class, "dummy.jar") .addClasses(RaAnnoEmptyRaXmlFromModuleTestCase.class, AbstractModuleDeploymentTestCaseSetup.class) .addAsManifestResource( new StringAsset( "Dependencies: wildflyee.api, org.jboss.as.controller-client, " + "org.jboss.as.controller, " + "org.jboss.as.connector, " + "org.jboss.dmr, " + "org.jboss.ironjacamar.ra16out, " + "org.jboss.remoting\n"), "MANIFEST.MF"); } @Resource(mappedName = JNDI_CF) private AnnoConnectionFactory connectionFactory; @Resource(mappedName = JNDI_AO) private AnnoAdminObject adminObject; @Test public void testGetConnection() throws Throwable { assertNotNull(connectionFactory); AnnoConnectionImpl connection = (AnnoConnectionImpl) connectionFactory.getConnection(); assertNotNull(connection); AnnoManagedConnectionFactory mcf = connection.getMCF(); assertNotNull(mcf); // first is updated during activation assertEquals((byte) 23, (byte) mcf.getFirst()); // second uses default assertEquals((short) 0, (short) mcf.getSecond()); connection.close(); } @Test public void testAdminOjbect() { assertNotNull(adminObject); assertEquals((long) 12345, (long) adminObject.getFirst()); assertEquals(true, adminObject.getSecond()); } }
10,696
46.96861
149
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/anno/NoRaAnnoTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.anno; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.Iterator; import java.util.List; import java.util.Set; import org.jboss.logging.Logger; import jakarta.annotation.Resource; import jakarta.resource.spi.ActivationSpec; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.connector.subsystems.resourceadapters.Namespace; import org.jboss.as.connector.subsystems.resourceadapters.ResourceAdapterSubsystemParser; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.test.integration.jca.annorar.AnnoActivationSpec; import org.jboss.as.test.integration.jca.annorar.AnnoAdminObject; import org.jboss.as.test.integration.jca.annorar.AnnoConnectionFactory; import org.jboss.as.test.integration.jca.annorar.AnnoConnectionImpl; import org.jboss.as.test.integration.jca.annorar.AnnoManagedConnectionFactory; import org.jboss.as.test.integration.jca.annorar.AnnoMessageListener; import org.jboss.as.test.integration.jca.annorar.AnnoMessageListener1; import org.jboss.as.test.integration.jca.annorar.AnnoResourceAdapter; import org.jboss.as.test.integration.management.base.AbstractMgmtServerSetupTask; import org.jboss.as.test.integration.management.base.AbstractMgmtTestBase; import org.jboss.as.test.shared.FileUtils; import org.jboss.dmr.ModelNode; import org.jboss.jca.common.metadata.spec.ConnectorImpl; import org.jboss.jca.core.spi.mdr.MetadataRepository; import org.jboss.jca.core.spi.rar.Endpoint; import org.jboss.jca.core.spi.rar.MessageListener; import org.jboss.jca.core.spi.rar.ResourceAdapterRepository; import org.jboss.msc.service.ServiceContainer; import org.jboss.msc.service.ServiceController; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * Activation of annotated RA * * @author <a href="mailto:[email protected]">Vladimir Rastseluev</a> */ @RunWith(Arquillian.class) @ServerSetup(NoRaAnnoTestCase.NoRaAnnoTestCaseSetup.class) public class NoRaAnnoTestCase { /** * The logger */ private static Logger log = Logger.getLogger("NoRaAnnoTestCase"); static class NoRaAnnoTestCaseSetup extends AbstractMgmtServerSetupTask { private ModelNode address; @Override public void doSetup(final ManagementClient managementClient) throws Exception { String xml = FileUtils.readFile(NoRaAnnoTestCase.class, "ra16anno.xml"); List<ModelNode> operations = xmlToModelOperations(xml, Namespace.RESOURCEADAPTERS_1_0.getUriString(), new ResourceAdapterSubsystemParser()); address = operations.get(1).get("address"); executeOperation(operationListToCompositeOperation(operations)); } @Override public void tearDown(final ManagementClient managementClient, final String containerId) throws Exception { remove(address); } } /** * Define the deployment * * @return The deployment archive * @throws Exception in case of error */ @Deployment public static ResourceAdapterArchive createDeployment() throws Exception { ResourceAdapterArchive raa = ShrinkWrap.create( ResourceAdapterArchive.class, "ra16anno.rar"); JavaArchive ja = ShrinkWrap.create(JavaArchive.class); ja.addClasses(NoRaAnnoTestCase.class); ja.addPackage(AbstractMgmtTestBase.class.getPackage()).addPackage( AnnoConnectionFactory.class.getPackage()); raa.addAsLibrary(ja) .addAsManifestResource( new StringAsset( "Dependencies: javax.inject.api,org.jboss.as.connector\n"), "MANIFEST.MF"); return raa; } /** * Resource */ @Resource(mappedName = "java:/eis/ra16anno") private AnnoConnectionFactory connectionFactory1; /** * Resource */ @Resource(mappedName = "java:/eis/ao/ra16anno") private AnnoAdminObject adminObject; @ArquillianResource ServiceContainer serviceContainer; /** * Test getConnection * * @throws Throwable Thrown if case of an error */ @Test public void testGetConnection1() throws Throwable { assertNotNull(connectionFactory1); AnnoConnectionImpl connection1 = (AnnoConnectionImpl) connectionFactory1 .getConnection(); assertNotNull(connection1); AnnoManagedConnectionFactory mcf = connection1.getMCF(); assertNotNull(mcf); log.trace("MCF:" + mcf + "//1//" + mcf.getFirst() + "//2//" + mcf.getSecond()); assertEquals((byte) 4, (byte) mcf.getFirst()); assertEquals((short) 0, (short) mcf.getSecond()); connection1.close(); } /** * Test admin objects * * @throws Throwable Thrown if case of an error */ @Test public void testAdminOjbect() throws Throwable { assertNotNull(adminObject); log.trace("AO:" + adminObject + "//1//" + adminObject.getFirst() + "//2//" + adminObject.getSecond()); assertEquals((long) 12345, (long) adminObject.getFirst()); assertEquals(false, adminObject.getSecond()); } /** * test activation 1 * * @throws Throwable Thrown if case of an error */ @Test public void testActivation1() throws Throwable { testActivation(AnnoMessageListener.class); } /** * test activation 2 * * @throws Throwable Thrown if case of an error */ @Test public void testActivation2() throws Throwable { testActivation(AnnoMessageListener1.class); } /** * Test activation * * @param clazz class name * @throws Throwable Thrown if case of an error */ public void testActivation(Class clazz) throws Throwable { ServiceController<?> controller = serviceContainer .getService(ConnectorServices.RA_REPOSITORY_SERVICE); assertNotNull(controller); ResourceAdapterRepository raRepository = (ResourceAdapterRepository) controller .getValue(); Set<String> ids = raRepository.getResourceAdapters(clazz); assertNotNull(ids); assertEquals(1, ids.size()); String piId = ids.iterator().next(); assertNotNull(piId); Endpoint endpoint = raRepository.getEndpoint(piId); assertNotNull(endpoint); List<MessageListener> listeners = raRepository .getMessageListeners(piId); assertNotNull(listeners); assertEquals(2, listeners.size()); MessageListener listener = listeners.get(0); MessageListener listener1 = listeners.get(1); ActivationSpec as = listener.getActivation().createInstance(); ActivationSpec as1 = listener1.getActivation().createInstance(); assertNotNull(as); assertNotNull(as.getResourceAdapter()); assertNotNull(as1); assertNotNull(as1.getResourceAdapter()); AnnoActivationSpec tas = (AnnoActivationSpec) as; log.trace("AS:" + tas + "//1//" + tas.getFirst() + "//2//" + tas.getSecond()); assertEquals(new Character('C'), tas.getFirst()); assertEquals(new Double(0.5), tas.getSecond()); assertTrue(tas.getResourceAdapter() instanceof AnnoResourceAdapter); AnnoResourceAdapter tra = (AnnoResourceAdapter) tas .getResourceAdapter(); log.trace("RA:" + tra + "//1//" + tra.getFirst() + "//2//" + tra.getSecond()); assertEquals("A", tra.getFirst()); assertEquals(new Integer(5), tra.getSecond()); } /** * Test metadata * * @throws Throwable Thrown if case of an error */ @Test public void testMetaData() throws Throwable { ServiceController<?> controller = serviceContainer .getService(ConnectorServices.IRONJACAMAR_MDR); assertNotNull(controller); MetadataRepository mdr = (MetadataRepository) controller.getValue(); assertNotNull(mdr); Set<String> ids = mdr.getResourceAdapters(); assertNotNull(ids); assertTrue(ids.size() > 0); String piId = getElementContaining(ids, "ra16anno"); assertNotNull(mdr.getResourceAdapter(piId)); assertTrue(mdr.getResourceAdapter(piId) instanceof ConnectorImpl); } /** * Checks Set if there is a String element, containing some substring and * returns it * * @param ids - Set * @param contain - substring * @return String */ public String getElementContaining(Set<String> ids, String contain) { Iterator<String> it = ids.iterator(); while (it.hasNext()) { String t = it.next(); if (t.contains(contain)) { return t; } } return null; } }
10,579
35.232877
91
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/poolattributes/DatasourceMinPoolAttributeTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. * */ package org.jboss.as.test.integration.jca.poolattributes; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import jakarta.annotation.Resource; import javax.sql.DataSource; import org.jboss.arquillian.container.test.api.ContainerController; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.connector.subsystems.common.pool.Constants; import org.jboss.as.connector.subsystems.datasources.WildFlyDataSource; import org.jboss.as.controller.client.ModelControllerClient; import org.jboss.as.test.integration.jca.JcaMgmtBase; import org.jboss.as.test.integration.jca.JcaMgmtServerSetupTask; import org.jboss.as.test.integration.jca.JcaTestsUtil; import org.jboss.as.test.integration.jca.datasource.Datasource; import org.jboss.as.test.integration.jca.datasource.DatasourceNonCcmTestCase; import org.jboss.as.test.integration.management.ManagementOperations; import org.jboss.as.test.integration.management.base.AbstractMgmtServerSetupTask; import org.jboss.as.test.integration.management.base.AbstractMgmtTestBase; import org.jboss.as.test.integration.management.base.ContainerResourceMgmtTestBase; import org.jboss.as.test.integration.management.util.MgmtOperationException; import org.jboss.as.test.shared.ServerReload; import org.jboss.dmr.ModelNode; import org.jboss.jca.adapters.jdbc.WrapperDataSource; import org.jboss.jca.core.api.connectionmanager.pool.PoolConfiguration; import org.jboss.remoting3.security.RemotingPermission; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import java.io.FilePermission; import java.lang.reflect.ReflectPermission; /** * Checks that pool attributes can be set and do (not) require a reload. * * @author <a href="mailto:[email protected]">Tomas Hofman</a> */ @RunWith(Arquillian.class) @ServerSetup(DatasourceMinPoolAttributeTestCase.DatasourceServerSetupTask.class) public class DatasourceMinPoolAttributeTestCase extends JcaMgmtBase { private static final String DS_NAME = "DS"; private static final ModelNode DS_ADDRESS = new ModelNode().add(SUBSYSTEM, "datasources") .add("data-source", DS_NAME); static { DS_ADDRESS.protect(); } @Deployment public static Archive<?> createDeployment() { JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "deployment.jar"); jar.addClasses( DatasourceNonCcmTestCase.class, Datasource.class, WildFlyDataSource.class, WrapperDataSource.class, JcaMgmtServerSetupTask.class, DatasourceMinPoolAttributeTestCase.class, AbstractMgmtServerSetupTask.class, AbstractMgmtTestBase.class, JcaMgmtBase.class, ContainerResourceMgmtTestBase.class, MgmtOperationException.class, ManagementOperations.class, JcaTestsUtil.class, ServerReload.class); jar.addAsManifestResource(new StringAsset("Dependencies: javax.inject.api," + "org.jboss.as.connector," + "org.jboss.as.controller," + "org.jboss.dmr," + // Needed for RemotingPermission class if security manager is enabled (System.getProperty("security.manager") == null ? "" : "org.jboss.remoting,") + "org.jboss.staxmapper," + "org.jboss.ironjacamar.api," + "org.jboss.ironjacamar.impl," + "org.jboss.ironjacamar.jdbcadapters\n"), "MANIFEST.MF"); jar.addAsManifestResource(createPermissionsXmlAsset( new RuntimePermission("accessDeclaredMembers"), new ReflectPermission("suppressAccessChecks"), new RemotingPermission("createEndpoint"), new RemotingPermission("connect"), new FilePermission(System.getProperty("jboss.inst") + "/standalone/tmp/auth/*", "read") ), "permissions.xml"); return jar; } @Resource(mappedName = "java:jboss/datasources/" + DS_NAME) private DataSource datasource; @ArquillianResource private ManagementClient managementClient; @ArquillianResource private static ContainerController container; @Override protected ModelControllerClient getModelControllerClient() { return managementClient.getControllerClient(); } @Test public void testModifyMinPoolAttribute() throws Exception { WrapperDataSource wrapperDataSource = JcaTestsUtil.extractWrapperDatasource((WildFlyDataSource) datasource); PoolConfiguration poolConfiguration = JcaTestsUtil.exctractPoolConfiguration(wrapperDataSource); // check initial values Assert.assertNotNull(poolConfiguration); Assert.assertEquals(0, poolConfiguration.getMinSize()); // modify values writeAttribute(DS_ADDRESS, Constants.MIN_POOL_SIZE.getName(), "4"); // check that server is in reload-required state ModelNode serverState = readAttribute(new ModelNode(), "server-state"); Assert.assertEquals("reload-required", serverState.asString()); // check that runtime was updated Assert.assertEquals(4, poolConfiguration.getMinSize()); } static class DatasourceServerSetupTask extends JcaMgmtServerSetupTask { @Override protected void doSetup(ManagementClient managementClient) throws Exception { setupDs(managementClient, DS_NAME, true); reload(); } private void setupDs(ManagementClient managementClient, String dsName, boolean jta) throws Exception { Datasource ds = Datasource.Builder(dsName).build(); ModelNode address = new ModelNode(); address.add("subsystem", "datasources"); address.add("data-source", dsName); ModelNode operation = new ModelNode(); operation.get(OP).set(ADD); operation.get(OP_ADDR).set(address); operation.get("jndi-name").set(ds.getJndiName()); operation.get("use-java-context").set("true"); operation.get("driver-name").set(ds.getDriverName()); operation.get("enabled").set("true"); operation.get("user-name").set(ds.getUserName()); operation.get("password").set(ds.getPassword()); operation.get("jta").set(jta); operation.get("use-ccm").set("true"); operation.get("connection-url").set(ds.getConnectionUrl()); managementClient.getControllerClient().execute(operation); } } }
8,468
41.989848
116
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/poolattributes/ResourceAdapterPoolAttributesTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. * */ package org.jboss.as.test.integration.jca.poolattributes; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import java.io.FilePermission; import java.lang.reflect.ReflectPermission; import java.util.List; import jakarta.annotation.Resource; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.connector.subsystems.common.pool.Constants; import org.jboss.as.connector.subsystems.resourceadapters.Namespace; import org.jboss.as.connector.subsystems.resourceadapters.ResourceAdapterSubsystemParser; import org.jboss.as.controller.client.ModelControllerClient; import org.jboss.as.test.integration.jca.JcaMgmtBase; import org.jboss.as.test.integration.jca.JcaMgmtServerSetupTask; import org.jboss.as.test.integration.jca.JcaTestsUtil; import org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyConnection; import org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyConnectionFactory; import org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyConnectionFactoryImpl; import org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyConnectionImpl; import org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyLocalTransaction; import org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyManagedConnection; import org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyManagedConnectionFactory; import org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyManagedConnectionMetaData; import org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyResourceAdapter; import org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyXAResource; import org.jboss.as.test.integration.management.ManagementOperations; import org.jboss.as.test.integration.management.base.AbstractMgmtServerSetupTask; import org.jboss.as.test.integration.management.base.AbstractMgmtTestBase; import org.jboss.as.test.integration.management.base.ContainerResourceMgmtTestBase; import org.jboss.as.test.integration.management.util.MgmtOperationException; import org.jboss.as.test.shared.FileUtils; import org.jboss.dmr.ModelNode; import org.jboss.jca.core.api.connectionmanager.pool.PoolConfiguration; import org.jboss.remoting3.security.RemotingPermission; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Checks that pool attributes can be set and do not require a reload. * * @author <a href="mailto:[email protected]">Tomas Hofman</a> */ @RunWith(Arquillian.class) @ServerSetup(ResourceAdapterPoolAttributesTestCase.ResourceAdapterCapacityPoliciesServerSetupTask.class) public class ResourceAdapterPoolAttributesTestCase extends JcaMgmtBase { private static final String RA_NAME = "pool-attributes-test.rar"; private static final ModelNode RA_ADDRESS = new ModelNode().add(SUBSYSTEM, "resource-adapters") .add("resource-adapter", RA_NAME); private static final ModelNode CONNECTION_ADDRESS = RA_ADDRESS.clone().add("connection-definitions", "Lazy"); static { RA_ADDRESS.protect(); CONNECTION_ADDRESS.protect(); } @Deployment public static Archive<?> createResourceAdapter() { ResourceAdapterArchive rar = ShrinkWrap.create(ResourceAdapterArchive.class, RA_NAME); rar.addAsManifestResource(LazyResourceAdapter.class.getPackage(), "ra-notx.xml", "ra.xml"); JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "pool-attributes-test.jar"); jar.addClass(LazyResourceAdapter.class) .addClass(LazyManagedConnectionFactory.class) .addClass(LazyManagedConnection.class) .addClass(LazyConnection.class) .addClass(LazyConnectionImpl.class) .addClass(LazyXAResource.class) .addClass(LazyLocalTransaction.class) .addClass(LazyManagedConnectionMetaData.class) .addClass(LazyConnectionFactory.class) .addClass(LazyConnectionFactoryImpl.class); jar.addClasses( ResourceAdapterPoolAttributesTestCase.class, AbstractMgmtServerSetupTask.class, JcaMgmtServerSetupTask.class, AbstractMgmtTestBase.class, JcaMgmtBase.class, ContainerResourceMgmtTestBase.class, MgmtOperationException.class, ManagementOperations.class, JcaTestsUtil.class); rar.addAsManifestResource(new StringAsset("Dependencies: javax.inject.api,org.jboss.as.connector," + "org.jboss.as.controller,org.jboss.dmr,org.jboss.staxmapper," + // Needed for RemotingPermission class if security manager is enabled (System.getProperty("security.manager") == null ? "" : "org.jboss.remoting,") + "org.jboss.ironjacamar.impl, org.jboss.ironjacamar.jdbcadapters\n"), "MANIFEST.MF"); rar.addAsManifestResource(createPermissionsXmlAsset( new RemotingPermission("createEndpoint"), new RemotingPermission("connect"), new RuntimePermission("accessDeclaredMembers"), new ReflectPermission("suppressAccessChecks"), new FilePermission(System.getProperty("jboss.inst") + "/standalone/tmp/auth/*", "read") ), "permissions.xml"); rar.addAsLibrary(jar); return rar; } @Resource(mappedName = "java:/eis/Lazy") private LazyConnectionFactory lcf; @ArquillianResource private ManagementClient managementClient; @Override protected ModelControllerClient getModelControllerClient() { return managementClient.getControllerClient(); } @Test public void testModifyPoolAttributes() throws Exception { PoolConfiguration poolConfiguration = JcaTestsUtil.exctractPoolConfiguration(lcf); // check initial values Assert.assertNotNull(poolConfiguration); Assert.assertEquals(2, poolConfiguration.getMinSize()); Assert.assertEquals(5, poolConfiguration.getMaxSize()); Assert.assertEquals(2, poolConfiguration.getInitialSize()); Assert.assertEquals(30000, poolConfiguration.getBlockingTimeout()); Assert.assertEquals(true, poolConfiguration.isFair()); Assert.assertEquals(false, poolConfiguration.isStrictMin()); // modify values writeAttribute(CONNECTION_ADDRESS, Constants.INITIAL_POOL_SIZE.getName(), "4"); writeAttribute(CONNECTION_ADDRESS, Constants.BLOCKING_TIMEOUT_WAIT_MILLIS.getName(), "10000"); writeAttribute(CONNECTION_ADDRESS, Constants.POOL_FAIR.getName(), "false"); writeAttribute(CONNECTION_ADDRESS, Constants.POOL_USE_STRICT_MIN.getName(), "true"); // check that server is not in reload-required state ModelNode serverState = readAttribute(new ModelNode(), "server-state"); Assert.assertEquals("running", serverState.asString()); // check that runtime was updated Assert.assertEquals(4, poolConfiguration.getInitialSize()); Assert.assertEquals(10000, poolConfiguration.getBlockingTimeout()); Assert.assertEquals(false, poolConfiguration.isFair()); Assert.assertEquals(true, poolConfiguration.isStrictMin()); writeAttribute(CONNECTION_ADDRESS, Constants.MIN_POOL_SIZE.getName(), "4"); writeAttribute(CONNECTION_ADDRESS, Constants.MAX_POOL_SIZE.getName(), "10"); // check that server is in reload-required state serverState = readAttribute(new ModelNode(), "server-state"); Assert.assertEquals("reload-required", serverState.asString()); ModelNode result = readAttribute(CONNECTION_ADDRESS, Constants.MIN_POOL_SIZE.getName()); Assert.assertEquals(4, result.asInt()); result = readAttribute(CONNECTION_ADDRESS, Constants.MAX_POOL_SIZE.getName()); Assert.assertEquals(10, result.asInt()); } static class ResourceAdapterCapacityPoliciesServerSetupTask extends JcaMgmtServerSetupTask { @Override public void doSetup(final ManagementClient managementClient) throws Exception { String xml = FileUtils.readFile(ResourceAdapterPoolAttributesTestCase.class, "ra-def.xml"); List<ModelNode> operations = xmlToModelOperations(xml, Namespace.RESOURCEADAPTERS_1_1.getUriString(), new ResourceAdapterSubsystemParser()); executeOperation(operationListToCompositeOperation(operations)); reload(); } } }
10,144
48.730392
152
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/poolattributes/DatasourcePoolAttributesTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. * */ package org.jboss.as.test.integration.jca.poolattributes; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import java.io.FilePermission; import java.lang.reflect.ReflectPermission; import jakarta.annotation.Resource; import javax.sql.DataSource; import org.jboss.arquillian.container.test.api.ContainerController; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.connector.subsystems.common.pool.Constants; import org.jboss.as.connector.subsystems.datasources.WildFlyDataSource; import org.jboss.as.controller.client.ModelControllerClient; import org.jboss.as.test.integration.jca.JcaMgmtBase; import org.jboss.as.test.integration.jca.JcaMgmtServerSetupTask; import org.jboss.as.test.integration.jca.JcaTestsUtil; import org.jboss.as.test.integration.jca.datasource.Datasource; import org.jboss.as.test.integration.jca.datasource.DatasourceNonCcmTestCase; import org.jboss.as.test.integration.management.ManagementOperations; import org.jboss.as.test.integration.management.base.AbstractMgmtServerSetupTask; import org.jboss.as.test.integration.management.base.AbstractMgmtTestBase; import org.jboss.as.test.integration.management.base.ContainerResourceMgmtTestBase; import org.jboss.as.test.integration.management.util.MgmtOperationException; import org.jboss.as.test.shared.ServerReload; import org.jboss.dmr.ModelNode; import org.jboss.jca.adapters.jdbc.WrapperDataSource; import org.jboss.jca.core.api.connectionmanager.pool.PoolConfiguration; import org.jboss.remoting3.security.RemotingPermission; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Checks that pool attributes can be set and do (not) require a reload. * * @author <a href="mailto:[email protected]">Tomas Hofman</a> */ @RunWith(Arquillian.class) @ServerSetup(DatasourcePoolAttributesTestCase.DatasourceServerSetupTask.class) public class DatasourcePoolAttributesTestCase extends JcaMgmtBase { private static final String DS_NAME = "DS"; private static final ModelNode DS_ADDRESS = new ModelNode().add(SUBSYSTEM, "datasources") .add("data-source", DS_NAME); static { DS_ADDRESS.protect(); } @Deployment public static Archive<?> createDeployment() { JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "deployment.jar"); jar.addClasses( DatasourceNonCcmTestCase.class, Datasource.class, WildFlyDataSource.class, WrapperDataSource.class, JcaMgmtServerSetupTask.class, DatasourcePoolAttributesTestCase.class, AbstractMgmtServerSetupTask.class, AbstractMgmtTestBase.class, JcaMgmtBase.class, ContainerResourceMgmtTestBase.class, MgmtOperationException.class, ManagementOperations.class, JcaTestsUtil.class, ServerReload.class); jar.addAsManifestResource(new StringAsset("Dependencies: javax.inject.api," + "org.jboss.as.connector," + "org.jboss.as.controller," + "org.jboss.dmr," + "org.jboss.staxmapper," + // Needed for RemotingPermission class if security manager is enabled (System.getProperty("security.manager") == null ? "" : "org.jboss.remoting,") + "org.jboss.ironjacamar.api," + "org.jboss.ironjacamar.impl," + "org.jboss.ironjacamar.jdbcadapters\n"), "MANIFEST.MF"); jar.addAsManifestResource(createPermissionsXmlAsset( new RemotingPermission("connect"), new RemotingPermission("createEndpoint"), new RuntimePermission("accessDeclaredMembers"), new ReflectPermission("suppressAccessChecks"), new FilePermission(System.getProperty("jboss.inst") + "/standalone/tmp/auth/*", "read")), "permissions.xml"); return jar; } @Resource(mappedName = "java:jboss/datasources/" + DS_NAME) private DataSource datasource; @ArquillianResource private ManagementClient managementClient; @ArquillianResource private static ContainerController container; @Override protected ModelControllerClient getModelControllerClient() { return managementClient.getControllerClient(); } /** * Checks that attributes not requiring reload can be set. */ @Test public void testModifyNonReloadAttributes() throws Exception { WrapperDataSource wrapperDataSource = JcaTestsUtil.extractWrapperDatasource((WildFlyDataSource) datasource); PoolConfiguration poolConfiguration = JcaTestsUtil.exctractPoolConfiguration(wrapperDataSource); // check initial values Assert.assertNotNull(poolConfiguration); Assert.assertEquals(0, poolConfiguration.getInitialSize()); Assert.assertEquals(30000, poolConfiguration.getBlockingTimeout()); Assert.assertEquals(true, poolConfiguration.isFair()); Assert.assertEquals(false, poolConfiguration.isStrictMin()); // modify values writeAttribute(DS_ADDRESS, Constants.INITIAL_POOL_SIZE.getName(), "4"); writeAttribute(DS_ADDRESS, Constants.BLOCKING_TIMEOUT_WAIT_MILLIS.getName(), "10000"); writeAttribute(DS_ADDRESS, Constants.POOL_FAIR.getName(), "false"); writeAttribute(DS_ADDRESS, Constants.POOL_USE_STRICT_MIN.getName(), "true"); // check that server is not in reload-required state ModelNode serverState = readAttribute(new ModelNode(), "server-state"); Assert.assertEquals("running", serverState.asString()); // check that runtime was updated Assert.assertEquals(4, poolConfiguration.getInitialSize()); Assert.assertEquals(10000, poolConfiguration.getBlockingTimeout()); Assert.assertEquals(false, poolConfiguration.isFair()); Assert.assertEquals(true, poolConfiguration.isStrictMin()); } static class DatasourceServerSetupTask extends JcaMgmtServerSetupTask { @Override protected void doSetup(ManagementClient managementClient) throws Exception { setupDs(managementClient, DS_NAME, true); reload(); } private void setupDs(ManagementClient managementClient, String dsName, boolean jta) throws Exception { Datasource ds = Datasource.Builder(dsName).build(); ModelNode address = new ModelNode(); address.add("subsystem", "datasources"); address.add("data-source", dsName); ModelNode operation = new ModelNode(); operation.get(OP).set(ADD); operation.get(OP_ADDR).set(address); operation.get("jndi-name").set(ds.getJndiName()); operation.get("use-java-context").set("true"); operation.get("driver-name").set(ds.getDriverName()); operation.get("enabled").set("true"); operation.get("user-name").set(ds.getUserName()); operation.get("password").set(ds.getPassword()); operation.get("jta").set(jta); operation.get("use-ccm").set("true"); operation.get("connection-url").set(ds.getConnectionUrl()); managementClient.getControllerClient().execute(operation); } } }
9,227
44.014634
116
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/poolattributes/DatasourceMaxPoolAttributeTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. * */ package org.jboss.as.test.integration.jca.poolattributes; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import jakarta.annotation.Resource; import javax.sql.DataSource; import org.jboss.arquillian.container.test.api.ContainerController; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.connector.subsystems.common.pool.Constants; import org.jboss.as.connector.subsystems.datasources.WildFlyDataSource; import org.jboss.as.controller.client.ModelControllerClient; import org.jboss.as.test.integration.jca.JcaMgmtBase; import org.jboss.as.test.integration.jca.JcaMgmtServerSetupTask; import org.jboss.as.test.integration.jca.JcaTestsUtil; import org.jboss.as.test.integration.jca.datasource.Datasource; import org.jboss.as.test.integration.jca.datasource.DatasourceNonCcmTestCase; import org.jboss.as.test.integration.management.ManagementOperations; import org.jboss.as.test.integration.management.base.AbstractMgmtServerSetupTask; import org.jboss.as.test.integration.management.base.AbstractMgmtTestBase; import org.jboss.as.test.integration.management.base.ContainerResourceMgmtTestBase; import org.jboss.as.test.integration.management.util.MgmtOperationException; import org.jboss.as.test.shared.ServerReload; import org.jboss.dmr.ModelNode; import org.jboss.jca.adapters.jdbc.WrapperDataSource; import org.jboss.jca.core.api.connectionmanager.pool.PoolConfiguration; import org.jboss.remoting3.security.RemotingPermission; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import java.io.FilePermission; import java.lang.reflect.ReflectPermission; /** * Checks that pool attributes can be set and do (not) require a reload. * * @author <a href="mailto:[email protected]">Tomas Hofman</a> */ @RunWith(Arquillian.class) @ServerSetup(DatasourceMaxPoolAttributeTestCase.DatasourceServerSetupTask.class) public class DatasourceMaxPoolAttributeTestCase extends JcaMgmtBase { private static final String DS_NAME = "DS"; private static final ModelNode DS_ADDRESS = new ModelNode().add(SUBSYSTEM, "datasources") .add("data-source", DS_NAME); static { DS_ADDRESS.protect(); } @Deployment public static Archive<?> createDeployment() { JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "deployment.jar"); jar.addClasses( DatasourceNonCcmTestCase.class, Datasource.class, WildFlyDataSource.class, WrapperDataSource.class, JcaMgmtServerSetupTask.class, DatasourceMaxPoolAttributeTestCase.class, AbstractMgmtServerSetupTask.class, AbstractMgmtTestBase.class, JcaMgmtBase.class, ContainerResourceMgmtTestBase.class, MgmtOperationException.class, ManagementOperations.class, JcaTestsUtil.class, ServerReload.class); jar.addAsManifestResource(new StringAsset("Dependencies: javax.inject.api," + "org.jboss.as.connector," + "org.jboss.as.controller," + "org.jboss.dmr," + // Needed for RemotingPermission class if security manager is enabled (System.getProperty("security.manager") == null ? "" : "org.jboss.remoting,") + "org.jboss.staxmapper," + "org.jboss.ironjacamar.api," + "org.jboss.ironjacamar.impl," + "org.jboss.ironjacamar.jdbcadapters\n"), "MANIFEST.MF"); jar.addAsManifestResource(createPermissionsXmlAsset( new RuntimePermission("accessDeclaredMembers"), new ReflectPermission("suppressAccessChecks"), new RemotingPermission("createEndpoint"), new RemotingPermission("connect"), new FilePermission(System.getProperty("jboss.inst") + "/standalone/tmp/auth/*", "read") ), "permissions.xml"); return jar; } @Resource(mappedName = "java:jboss/datasources/" + DS_NAME) private DataSource datasource; @ArquillianResource private ManagementClient managementClient; @ArquillianResource private static ContainerController container; @Override protected ModelControllerClient getModelControllerClient() { return managementClient.getControllerClient(); } @Test public void testModifyMinPoolAttribute() throws Exception { WrapperDataSource wrapperDataSource = JcaTestsUtil.extractWrapperDatasource((WildFlyDataSource) datasource); PoolConfiguration poolConfiguration = JcaTestsUtil.exctractPoolConfiguration(wrapperDataSource); // check initial values Assert.assertNotNull(poolConfiguration); Assert.assertEquals(20, poolConfiguration.getMaxSize()); // modify values writeAttribute(DS_ADDRESS, Constants.MAX_POOL_SIZE.getName(), "10"); // check that server is reload-required state ModelNode serverState = readAttribute(new ModelNode(), "server-state"); Assert.assertEquals("reload-required", serverState.asString()); // check that runtime was updated Assert.assertEquals(10, poolConfiguration.getMaxSize()); } static class DatasourceServerSetupTask extends JcaMgmtServerSetupTask { @Override protected void doSetup(ManagementClient managementClient) throws Exception { setupDs(managementClient, DS_NAME, true); reload(); } private void setupDs(ManagementClient managementClient, String dsName, boolean jta) throws Exception { Datasource ds = Datasource.Builder(dsName).build(); ModelNode address = new ModelNode(); address.add("subsystem", "datasources"); address.add("data-source", dsName); ModelNode operation = new ModelNode(); operation.get(OP).set(ADD); operation.get(OP_ADDR).set(address); operation.get("jndi-name").set(ds.getJndiName()); operation.get("use-java-context").set("true"); operation.get("driver-name").set(ds.getDriverName()); operation.get("enabled").set("true"); operation.get("user-name").set(ds.getUserName()); operation.get("password").set(ds.getPassword()); operation.get("jta").set(jta); operation.get("use-ccm").set("true"); operation.get("connection-url").set(ds.getConnectionUrl()); managementClient.getControllerClient().execute(operation); } } }
8,469
41.777778
116
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/security/DsWithElytronAuthContextTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.security; import static org.junit.Assert.assertNotNull; import javax.naming.InitialContext; import javax.sql.DataSource; import java.sql.Connection; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Test; import org.junit.runner.RunWith; import org.wildfly.test.security.common.AbstractElytronSetupTask; import org.wildfly.test.security.common.elytron.ConfigurableElement; import org.wildfly.test.security.common.elytron.CredentialReference; import org.wildfly.test.security.common.elytron.MatchRules; import org.wildfly.test.security.common.elytron.SimpleAuthConfig; import org.wildfly.test.security.common.elytron.SimpleAuthContext; /** * Data source with security domain test JBQA-5952 * * @author <a href="mailto:[email protected]"> Vladimir Rastseluev</a> */ @RunWith(Arquillian.class) @ServerSetup(DsWithElytronAuthContextTestCase.ElytronSetup.class) public class DsWithElytronAuthContextTestCase { private static final String AUTH_CONFIG = "MyAuthConfig"; private static final String AUTH_CONTEXT = "MyAuthContext"; private static final String DATABASE_USER = "elytron"; private static final String DATABASE_PASSWORD = "passWD12#$"; private static final String DATASOURCE_NAME = "ElytronDSTest"; static class ElytronSetup extends AbstractElytronSetupTask { @Override protected ConfigurableElement[] getConfigurableElements() { final CredentialReference credRefPwd = CredentialReference.builder().withClearText(DATABASE_PASSWORD).build(); final ConfigurableElement authenticationConfiguration = SimpleAuthConfig.builder().withName(AUTH_CONFIG) .withAuthenticationName(DATABASE_USER).withCredentialReference(credRefPwd).build(); final MatchRules matchRules = MatchRules.builder().withAuthenticationConfiguration(AUTH_CONFIG).build(); final ConfigurableElement authenticationContext = SimpleAuthContext.builder().withName(AUTH_CONTEXT). withMatchRules(matchRules).build(); return new ConfigurableElement[] {authenticationConfiguration, authenticationContext}; } } @Deployment public static Archive<?> deployment() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "single.jar").addClasses(DsWithElytronAuthContextTestCase.class); jar.addClasses(AbstractElytronSetupTask.class); return ShrinkWrap.create(EnterpriseArchive.class, "test.ear").addAsLibrary(jar) .addAsManifestResource(DsWithElytronAuthContextTestCase.class.getPackage(), "security-ds-elytron.xml", "security-ds.xml"); } @ArquillianResource private InitialContext ctx; @Test public void deploymentTest() throws Exception { DataSource ds = (DataSource) ctx.lookup("java:jboss/datasources/" + DATASOURCE_NAME); Connection con = null; try { con = ds.getConnection(); assertNotNull(con); } finally { if (con != null) { con.close(); } } } }
4,467
42.803922
138
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/security/WildFlyActivationRaWithElytronAuthContextTestCase.java
/* * * Copyright 2017 Red Hat, 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 org.jboss.as.test.integration.jca.security; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS; import static org.junit.Assert.assertNotNull; import java.io.IOException; import jakarta.annotation.Resource; import jakarta.resource.cci.Connection; import javax.security.auth.PrivateCredentialPermission; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.api.ServerSetupTask; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.client.ModelControllerClient; import org.jboss.as.controller.client.helpers.ClientConstants; import org.jboss.as.controller.client.helpers.Operations; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.test.integration.jca.rar.MultipleConnectionFactory1; import org.jboss.as.test.shared.PermissionUtils; import org.jboss.dmr.ModelNode; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.wildfly.test.security.common.AbstractElytronSetupTask; import org.wildfly.test.security.common.elytron.ConfigurableElement; import org.wildfly.test.security.common.elytron.CredentialReference; import org.wildfly.test.security.common.elytron.MatchRules; import org.wildfly.test.security.common.elytron.SimpleAuthConfig; import org.wildfly.test.security.common.elytron.SimpleAuthContext; /** * Test for RA with elytron security domain, RA is activated using resource-adapter subsystem * * @author Flavia Rainone */ @RunWith(Arquillian.class) @ServerSetup({WildFlyActivationRaWithElytronAuthContextTestCase.ElytronSetup.class, WildFlyActivationRaWithElytronAuthContextTestCase.RaSetup.class}) public class WildFlyActivationRaWithElytronAuthContextTestCase { private static final String AUTH_CONFIG = "MyAuthConfig"; private static final String AUTH_CONTEXT = "MyAuthContext"; private static final String CREDENTIAL = "sa"; private static final String CONN_DEF_JNDI_NAME = "java:jboss/wf-ra-elytron-security"; static class ElytronSetup extends AbstractElytronSetupTask { @Override protected ConfigurableElement[] getConfigurableElements() { final CredentialReference credRefPwd = CredentialReference.builder().withClearText(CREDENTIAL).build(); final ConfigurableElement authenticationConfiguration = SimpleAuthConfig.builder().withName(AUTH_CONFIG) .withAuthenticationName(CREDENTIAL).withCredentialReference(credRefPwd).build(); final MatchRules matchRules = MatchRules.builder().withAuthenticationConfiguration(AUTH_CONFIG).build(); final ConfigurableElement authenticationContext = SimpleAuthContext.builder().withName(AUTH_CONTEXT). withMatchRules(matchRules).build(); return new ConfigurableElement[]{authenticationConfiguration, authenticationContext}; } } static class RaSetup implements ServerSetupTask { private static final PathAddress RA_ADDRESS = PathAddress.pathAddress(ModelDescriptionConstants.SUBSYSTEM, "resource-adapters") .append("resource-adapter", "wf-ra-elytron-security"); @Override public void setup(ManagementClient managementClient, String containerId) throws Exception { ModelControllerClient mcc = managementClient.getControllerClient(); addResourceAdapter(mcc); addConnectionDefinition(mcc); } @Override public void tearDown(ManagementClient managementClient, String containerId) throws Exception { removeResourceAdapterSilently(managementClient.getControllerClient()); } private void addResourceAdapter(ModelControllerClient client) throws IOException { ModelNode addRaOperation = Operations.createAddOperation(RA_ADDRESS.toModelNode()); addRaOperation.get("archive").set("wf-ra-ely-security.rar"); addRaOperation.get("transaction-support").set("NoTransaction"); ModelNode response = execute(addRaOperation, client); Assert.assertEquals(response.toString(), SUCCESS, response.get(OUTCOME).asString()); } private void addConnectionDefinition(ModelControllerClient client) throws IOException { PathAddress connectionDefinitionAddress = RA_ADDRESS.append("connection-definitions", "Pool1"); ModelNode addConnectionDefinitionOperation = Operations.createAddOperation(connectionDefinitionAddress.toModelNode()); addConnectionDefinitionOperation.get("class-name").set("org.jboss.as.test.integration.jca.rar.MultipleManagedConnectionFactoryWithSubjectVerification"); addConnectionDefinitionOperation.get("jndi-name").set(CONN_DEF_JNDI_NAME); addConnectionDefinitionOperation.get("elytron-enabled").set("true"); addConnectionDefinitionOperation.get("authentication-context").set(AUTH_CONTEXT); ModelNode response = execute(addConnectionDefinitionOperation, client); Assert.assertEquals(response.toString(), SUCCESS, response.get(OUTCOME).asString()); } private void removeResourceAdapterSilently(ModelControllerClient client) throws IOException { ModelNode removeRaOperation = Operations.createRemoveOperation(RA_ADDRESS.toModelNode()); removeRaOperation.get(ClientConstants.OPERATION_HEADERS).get("allow-resource-service-restart").set("true"); client.execute(removeRaOperation); } private ModelNode execute(ModelNode operation, ModelControllerClient client) throws IOException { return client.execute(operation); } } @Deployment public static Archive<?> deploymentSingleton() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "single.jar") .addClass(WildFlyActivationRaWithElytronAuthContextTestCase.class) .addPackage(MultipleConnectionFactory1.class.getPackage()); jar.addClasses(AbstractElytronSetupTask.class); final ResourceAdapterArchive rar = ShrinkWrap.create(ResourceAdapterArchive.class, "wf-ra-ely-security.rar") .addAsLibrary(jar) .addAsManifestResource(WildFlyActivationRaWithElytronAuthContextTestCase.class.getPackage(), "ra.xml", "ra.xml") .addAsManifestResource(new StringAsset("Dependencies: org.jboss.dmr, org.jboss.as.controller, org.jboss.as.controller-client\n"), "MANIFEST.MF"); rar.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset( new PrivateCredentialPermission("jakarta.resource.spi.security.PasswordCredential org.wildfly.security.auth.principal.NamePrincipal \"sa\"", "read")), "permissions.xml"); return rar; } @Resource(mappedName = CONN_DEF_JNDI_NAME) private MultipleConnectionFactory1 connectionFactory1; @ArquillianResource private ManagementClient client; @Test public void deploymentTest() throws Exception { assertNotNull("CF1 not found", connectionFactory1); Connection cci = connectionFactory1.getConnection(); assertNotNull("Cannot obtain connection", cci); cci.close(); } }
8,386
49.221557
186
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/security/TestBean.java
/* * * Copyright 2017 Red Hat, 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 org.jboss.as.test.integration.jca.security; import jakarta.annotation.security.DeclareRoles; import jakarta.annotation.security.RolesAllowed; import jakarta.ejb.Stateless; import org.jboss.ejb3.annotation.SecurityDomain; @Stateless @SecurityDomain("RaRealm") @DeclareRoles({"eis-role"}) public class TestBean { @RolesAllowed("eis-role") public boolean test() { return true; } }
1,012
26.378378
75
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/security/workmanager/AbstractJcaSetup.java
/* * * Copyright 2017 Red Hat, 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 org.jboss.as.test.integration.jca.security.workmanager; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS; import java.io.IOException; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.client.ModelControllerClient; import org.jboss.as.controller.client.helpers.Operations; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.test.shared.SnapshotRestoreSetupTask; import org.jboss.dmr.ModelNode; import org.junit.Assert; public abstract class AbstractJcaSetup extends SnapshotRestoreSetupTask { private static final PathAddress JCA_SUBSYSTEM_ADDRESS = PathAddress.pathAddress(ModelDescriptionConstants.SUBSYSTEM, "jca"); @Override public void doSetup(ManagementClient managementClient, String containerId) throws Exception { ModelControllerClient mcc = managementClient.getControllerClient(); addWM(mcc); addThreadPool(mcc); addBootstrapContext(mcc); } private void addWM(ModelControllerClient client) throws IOException { ModelNode addWMOperation = Operations.createAddOperation(getWorkManagerAddress().toModelNode()); addWMOperation.get("name").set(getWorkManagerName()); if(getElytronEnabled() != null) addWMOperation.get("elytron-enabled").set(getElytronEnabled()); ModelNode response = execute(addWMOperation, client); Assert.assertEquals(response.toString(), SUCCESS, response.get(OUTCOME).asString()); } private void addThreadPool(ModelControllerClient client) throws IOException { PathAddress shortRunningThreads = getWorkManagerAddress().append("short-running-threads", getWorkManagerName()); ModelNode addShortRunningThreadsOperation = Operations.createAddOperation(shortRunningThreads.toModelNode()); addShortRunningThreadsOperation.get("core-threads").set("20"); addShortRunningThreadsOperation.get("queue-length").set("20"); addShortRunningThreadsOperation.get("max-threads").set("20"); ModelNode response = execute(addShortRunningThreadsOperation, client); Assert.assertEquals(response.toString(), SUCCESS, response.get(OUTCOME).asString()); } private void addBootstrapContext(ModelControllerClient client) throws IOException { ModelNode addBootstrapCtxOperation = Operations.createAddOperation(getBootstrapContextAddress().toModelNode()); addBootstrapCtxOperation.get("name").set(getBootstrapContextName()); addBootstrapCtxOperation.get("workmanager").set(getWorkManagerName()); ModelNode response = execute(addBootstrapCtxOperation, client); Assert.assertEquals(response.toString(), SUCCESS, response.get(OUTCOME).asString()); } private ModelNode execute(ModelNode operation, ModelControllerClient client) throws IOException { return client.execute(operation); } private PathAddress getWorkManagerAddress() { return JCA_SUBSYSTEM_ADDRESS.append("workmanager", getWorkManagerName()); } private PathAddress getBootstrapContextAddress() { return JCA_SUBSYSTEM_ADDRESS.append("bootstrap-context", getBootstrapContextName()); } protected abstract String getWorkManagerName(); protected abstract String getBootstrapContextName(); protected abstract Boolean getElytronEnabled(); }
4,139
43.516129
129
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/security/workmanager/WildFlyActivationRaWithWMElytronSecurityDomainWorkManagerElytronUnconfiguredTestCase.java
/* * * Copyright 2017 Red Hat, 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 org.jboss.as.test.integration.jca.security.workmanager; import java.util.function.Consumer; import org.jboss.arquillian.container.test.api.Deployer; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.test.integration.jca.rar.MultipleConnectionFactory1; import org.jboss.as.test.integration.jca.security.WildFlyActivationRaWithElytronAuthContextTestCase; import org.jboss.dmr.ModelNode; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive; import org.junit.Test; import org.junit.runner.RunWith; import org.wildfly.test.security.common.AbstractElytronSetupTask; import org.wildfly.test.security.common.elytron.ConfigurableElement; import org.wildfly.test.security.common.elytron.PropertyFileBasedDomain; /** * Test security inflow with Jakarta Connectors work manager where RA is configured with Elytron security domain * and Workmanager is configured with Elytron security explicitly configured (it doesn't have elytron-enabled=true). * Default workmanager behavior if unconfigured is elytron is enabled so this should deploy successfully. */ @RunWith(Arquillian.class) @ServerSetup({ WildFlyActivationRaWithWMElytronSecurityDomainWorkManagerElytronUnconfiguredTestCase.ElytronSetup.class, WildFlyActivationRaWithWMElytronSecurityDomainWorkManagerElytronUnconfiguredTestCase.JcaSetup.class, WildFlyActivationRaWithWMElytronSecurityDomainWorkManagerElytronUnconfiguredTestCase.RaSetup.class}) @RunAsClient public class WildFlyActivationRaWithWMElytronSecurityDomainWorkManagerElytronUnconfiguredTestCase { private static final String ADMIN_OBJ_JNDI_NAME = "java:jboss/admObj"; private static final String WM_ELYTRON_SECURITY_DOMAIN_NAME = "RaRealmElytron"; private static final String BOOTSTRAP_CTX_NAME = "wrongContext"; static class ElytronSetup extends AbstractElytronSetupTask { @Override protected ConfigurableElement[] getConfigurableElements() { final PropertyFileBasedDomain domain = PropertyFileBasedDomain.builder() .withName(WM_ELYTRON_SECURITY_DOMAIN_NAME) .withUser("rauser", "rauserpassword") .build(); return new ConfigurableElement[]{domain}; } } static class JcaSetup extends AbstractJcaSetup { private static final String WM_NAME = "wrongWM"; @Override protected String getWorkManagerName() { return WM_NAME; } @Override protected String getBootstrapContextName() { return BOOTSTRAP_CTX_NAME; } @Override protected Boolean getElytronEnabled() { return null; } } static class RaSetup extends AbstractRaSetup { private static final String RA_NAME = "wf-ra-wm-security-domain"; @Override protected String getResourceAdapterName() { return RA_NAME; } @Override protected String getBootstrapContextName() { return BOOTSTRAP_CTX_NAME; } @Override protected String getAdminObjectJNDIName() { return ADMIN_OBJ_JNDI_NAME; } @Override protected Consumer<ModelNode> getAddRAOperationConsumer() { return addRaOperation -> { addRaOperation.get("wm-security").set(true); addRaOperation.get("wm-elytron-security-domain").set(WM_ELYTRON_SECURITY_DOMAIN_NAME); addRaOperation.get("wm-security-default-principal").set("wm-default-principal"); addRaOperation.get("wm-security-default-groups").set(new ModelNode().setEmptyList().add("wm-default-group")); }; } } @Deployment(name = "wf-ra-wm-security-domain-rar", testable = false, managed = false) public static Archive<?> rarDeployment() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "single.jar") .addPackage(MultipleConnectionFactory1.class.getPackage()); final ResourceAdapterArchive rar = ShrinkWrap.create(ResourceAdapterArchive.class, "wf-ra-wm-security-domain-rar.rar").addAsLibrary(jar) .addAsManifestResource(WildFlyActivationRaWithElytronAuthContextTestCase.class.getPackage(), "ra.xml", "ra.xml"); return rar; } @ArquillianResource private Deployer deployer; @Test public void testUnconfiguredElytron() throws Throwable { deployer.deploy("wf-ra-wm-security-domain-rar"); try { deployer.undeploy("wf-ra-wm-security-domain-rar"); } catch (Exception ex) { // ignore } } }
5,617
38.286713
144
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/security/workmanager/AbstractRaSetup.java
/* * * Copyright 2017 Red Hat, 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 org.jboss.as.test.integration.jca.security.workmanager; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS; import java.io.IOException; import java.util.function.Consumer; import org.jboss.as.arquillian.api.ServerSetupTask; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.client.ModelControllerClient; import org.jboss.as.controller.client.helpers.ClientConstants; import org.jboss.as.controller.client.helpers.Operations; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.dmr.ModelNode; import org.junit.Assert; public abstract class AbstractRaSetup implements ServerSetupTask { @Override public void setup(ManagementClient managementClient, String containerId) throws Exception { ModelControllerClient mcc = managementClient.getControllerClient(); addResourceAdapter(mcc); addAdminObject(mcc); } @Override public void tearDown(ManagementClient managementClient, String containerId) throws Exception { removeResourceAdapterSilently(managementClient.getControllerClient()); } private void addResourceAdapter(ModelControllerClient client) throws IOException { ModelNode addRaOperation = Operations.createAddOperation(getResourceAdapterAddress().toModelNode()); addRaOperation.get("archive").set("wf-ra-wm-security-domain-rar.rar"); addRaOperation.get("bootstrap-context").set(getBootstrapContextName()); addRaOperation.get("transaction-support").set("NoTransaction"); getAddRAOperationConsumer().accept(addRaOperation); ModelNode response = execute(addRaOperation, client); Assert.assertEquals(response.toString(), SUCCESS, response.get(OUTCOME).asString()); } private void addAdminObject(ModelControllerClient client) throws IOException { PathAddress adminObjectAddress = getResourceAdapterAddress().append("admin-objects", "admObj"); ModelNode addAdminObjectOperation = Operations.createAddOperation(adminObjectAddress.toModelNode()); addAdminObjectOperation.get("class-name").set("org.jboss.as.test.integration.jca.rar.MultipleAdminObject1Impl"); addAdminObjectOperation.get("jndi-name").set(getAdminObjectJNDIName()); ModelNode response = execute(addAdminObjectOperation, client); Assert.assertEquals(response.toString(), SUCCESS, response.get(OUTCOME).asString()); } private void removeResourceAdapterSilently(ModelControllerClient client) throws IOException { ModelNode removeRaOperation = Operations.createRemoveOperation(getResourceAdapterAddress().toModelNode()); removeRaOperation.get(ClientConstants.OPERATION_HEADERS).get("allow-resource-service-restart").set("true"); client.execute(removeRaOperation); } private ModelNode execute(ModelNode operation, ModelControllerClient client) throws IOException { return client.execute(operation); } private PathAddress getResourceAdapterAddress() { return PathAddress.pathAddress(ModelDescriptionConstants.SUBSYSTEM, "resource-adapters") .append("resource-adapter", getResourceAdapterName()); } protected abstract String getResourceAdapterName(); protected abstract String getBootstrapContextName(); protected abstract String getAdminObjectJNDIName(); protected abstract Consumer<ModelNode> getAddRAOperationConsumer(); }
4,217
43.4
120
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/security/workmanager/WildFlyActivationRaWithWMElytronSecurityDomainWorkManagerElytronEnabledTestCase.java
/* * * Copyright 2017 Red Hat, 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 org.jboss.as.test.integration.jca.security.workmanager; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.isA; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import java.io.IOException; import java.security.Principal; import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.function.Consumer; import java.util.stream.Collectors; import java.util.stream.Stream; import jakarta.annotation.Resource; import jakarta.ejb.EJB; import jakarta.ejb.EJBAccessException; import jakarta.resource.spi.work.SecurityContext; import jakarta.resource.spi.work.Work; import jakarta.resource.spi.work.WorkContext; import jakarta.resource.spi.work.WorkContextProvider; import jakarta.resource.spi.work.WorkManager; import javax.security.auth.AuthPermission; import javax.security.auth.Subject; import javax.security.auth.callback.CallbackHandler; import jakarta.security.auth.message.callback.CallerPrincipalCallback; import jakarta.security.auth.message.callback.GroupPrincipalCallback; import org.hamcrest.MatcherAssert; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.OperateOnDeployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.api.ServerSetupTask; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.client.ModelControllerClient; import org.jboss.as.controller.client.helpers.Operations; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.test.integration.jca.rar.MultipleAdminObject1; import org.jboss.as.test.integration.jca.rar.MultipleAdminObject1Impl; import org.jboss.as.test.integration.jca.rar.MultipleConnectionFactory1; import org.jboss.as.test.integration.jca.rar.MultipleResourceAdapter; import org.jboss.as.test.integration.jca.security.TestBean; import org.jboss.as.test.integration.jca.security.WildFlyActivationRaWithElytronAuthContextTestCase; import org.jboss.as.test.integration.security.common.AbstractSecurityDomainSetup; import org.jboss.dmr.ModelNode; import org.jboss.jca.core.security.SimplePrincipal; import org.jboss.jca.core.spi.security.SecurityIntegration; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.wildfly.security.auth.permission.ChangeRoleMapperPermission; import org.wildfly.security.auth.principal.NamePrincipal; import org.wildfly.security.permission.ElytronPermission; import org.wildfly.test.security.common.AbstractElytronSetupTask; import org.wildfly.test.security.common.elytron.ConfigurableElement; import org.wildfly.test.security.common.elytron.PropertyFileBasedDomain; /** * Test security inflow with Jakarta Connectors work manager using Elytron security domain */ @RunWith(Arquillian.class) @ServerSetup({ WildFlyActivationRaWithWMElytronSecurityDomainWorkManagerElytronEnabledTestCase.ElytronSetup.class, WildFlyActivationRaWithWMElytronSecurityDomainWorkManagerElytronEnabledTestCase.Ejb3Setup.class, WildFlyActivationRaWithWMElytronSecurityDomainWorkManagerElytronEnabledTestCase.JcaSetup.class, WildFlyActivationRaWithWMElytronSecurityDomainWorkManagerElytronEnabledTestCase.RaSetup.class}) public class WildFlyActivationRaWithWMElytronSecurityDomainWorkManagerElytronEnabledTestCase { private static final String ADMIN_OBJ_JNDI_NAME = "java:jboss/admObj"; private static final String WM_ELYTRON_SECURITY_DOMAIN_NAME = "RaRealmElytron"; private static final String WM_EJB3_SECURITY_DOMAIN_NAME = "RaRealm"; private static final String BOOTSTRAP_CTX_NAME = "customContext"; static class ElytronSetup extends AbstractElytronSetupTask { @Override protected ConfigurableElement[] getConfigurableElements() { final PropertyFileBasedDomain domain = PropertyFileBasedDomain.builder() .withName(WM_ELYTRON_SECURITY_DOMAIN_NAME) .withUser("rauser", "rauserpassword") .build(); return new ConfigurableElement[]{domain}; } } static class Ejb3Setup implements ServerSetupTask { private static final PathAddress EJB3_SUBSYSTEM_ADDRESS = PathAddress.pathAddress(ModelDescriptionConstants.SUBSYSTEM, "ejb3"); private static final PathAddress EJB3_APP_SEC_DOMAIN_ADDRESS = EJB3_SUBSYSTEM_ADDRESS.append("application-security-domain", WM_EJB3_SECURITY_DOMAIN_NAME); @Override public void setup(ManagementClient managementClient, String containerId) throws Exception { ModelControllerClient mcc = managementClient.getControllerClient(); addApplicationSecurityDomain(mcc); } @Override public void tearDown(ManagementClient managementClient, String containerId) throws Exception { ModelControllerClient mcc = managementClient.getControllerClient(); removeApplicationSecurityDomainSilently(mcc); } private void addApplicationSecurityDomain(ModelControllerClient client) throws Exception { ModelNode addAppSecDomainOperation = Operations.createAddOperation(EJB3_APP_SEC_DOMAIN_ADDRESS.toModelNode()); addAppSecDomainOperation.get("security-domain").set(WM_ELYTRON_SECURITY_DOMAIN_NAME); ModelNode response = execute(addAppSecDomainOperation, client); Assert.assertEquals(response.toString(), SUCCESS, response.get(OUTCOME).asString()); } private void removeApplicationSecurityDomainSilently(ModelControllerClient client) throws IOException { ModelNode removeBootstrapCtxOperation = Operations.createRemoveOperation(EJB3_APP_SEC_DOMAIN_ADDRESS.toModelNode()); client.execute(removeBootstrapCtxOperation); } private ModelNode execute(ModelNode operation, ModelControllerClient client) throws IOException { return client.execute(operation); } } static class JcaSetup extends AbstractJcaSetup { private static final String WM_NAME = "customWM"; @Override protected String getWorkManagerName() { return WM_NAME; } @Override protected String getBootstrapContextName() { return BOOTSTRAP_CTX_NAME; } @Override protected Boolean getElytronEnabled() { return true; } } static class RaSetup extends AbstractRaSetup { private static final String RA_NAME = "wf-ra-wm-security-domain"; @Override protected String getResourceAdapterName() { return RA_NAME; } @Override protected String getBootstrapContextName() { return BOOTSTRAP_CTX_NAME; } @Override protected String getAdminObjectJNDIName() { return ADMIN_OBJ_JNDI_NAME; } @Override protected Consumer<ModelNode> getAddRAOperationConsumer() { return addRaOperation -> { addRaOperation.get("wm-security").set(true); addRaOperation.get("wm-elytron-security-domain").set(WM_ELYTRON_SECURITY_DOMAIN_NAME); addRaOperation.get("wm-security-default-principal").set("wm-default-principal"); addRaOperation.get("wm-security-default-groups").set(new ModelNode().setEmptyList().add("wm-default-group")); }; } } @Deployment(name = "wf-ra-wm-security-domain-rar", testable = false, order = 1) public static Archive<?> rarDeployment() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "single.jar") .addPackage(MultipleConnectionFactory1.class.getPackage()); final ResourceAdapterArchive rar = ShrinkWrap.create(ResourceAdapterArchive.class, "wf-ra-wm-security-domain-rar.rar").addAsLibrary(jar) .addAsManifestResource(WildFlyActivationRaWithElytronAuthContextTestCase.class.getPackage(), "ra.xml", "ra.xml"); return rar; } @Deployment(name = "ejb", order = 2) public static Archive<?> ejbDeployment() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "wf-ra-wm-security-domain-ejb.jar") .addClass(WildFlyActivationRaWithWMElytronSecurityDomainWorkManagerElytronEnabledTestCase.class) .addClass(AbstractElytronSetupTask.class) .addClass(AbstractJcaSetup.class) .addClass(AbstractRaSetup.class); jar.addClasses(AbstractSecurityDomainSetup.class, TestBean.class); jar.addAsManifestResource(new StringAsset("Dependencies: org.jboss.ironjacamar.api,deployment.wf-ra-wm-security-domain-rar.rar\n"), "MANIFEST.MF"); jar.addAsManifestResource(createPermissionsXmlAsset( new ElytronPermission("createAdHocIdentity"), new ChangeRoleMapperPermission("ejb"), new AuthPermission("modifyPrincipals") ), "permissions.xml"); return jar; } @Resource(mappedName = ADMIN_OBJ_JNDI_NAME) private MultipleAdminObject1 adminObject; @EJB private TestBean bean; @Rule public ExpectedException expectedException = ExpectedException.none(); @Test @OperateOnDeployment("ejb") public void testValidRole() throws Exception { WorkManager wm = getWorkManager(); MyWork myWork = new MyWork(wm, bean, "eis", "eis-role"); wm.doWork(myWork); // This is different from legacy security. // Legacy security merges default default principals and groups // (wm-security-default-principal and wm-security-default-groups) // with those defined by SecurityContext. // Elytron ignores configured defaults when there are already specific principal and groups set verifyUsers(myWork, "eis"); verifyRoles(myWork, "eis-role"); } @Test @OperateOnDeployment("ejb") public void testInvalidRole() throws Exception { expectedException.expectCause(isA(EJBAccessException.class)); expectedException.expectMessage(containsString("WFLYEJB0364")); WorkManager wm = getWorkManager(); MyWork myWork = new MyWork(wm, bean, "eis", "invalid-role"); wm.doWork(myWork); } private WorkManager getWorkManager() { MultipleAdminObject1Impl ao = (MultipleAdminObject1Impl) adminObject; MultipleResourceAdapter ra = (MultipleResourceAdapter) ao.getResourceAdapter(); return ra.getWorkManager(); } private void verifyUsers(MyWork work, String... expectedUsers) { Set<Principal> principals = work.getPrincipals(); Set<Principal> expectedPrincipals = Stream.of(expectedUsers).map(NamePrincipal::new).collect(Collectors.toSet()); MatcherAssert.assertThat(principals, is(expectedPrincipals)); } private void verifyRoles(MyWork work, String... expectedRoles) { String[] roles = work.getRoles(); MatcherAssert.assertThat(roles, is(expectedRoles)); } public static class MyWork implements Work, WorkContextProvider { private static final long serialVersionUID = 1L; private final WorkManager wm; private Set<Principal> principals; private String[] roles; private final TestBean bean; private final String username; private final String role; public MyWork(WorkManager wm, TestBean bean, String username, String role) { this.wm = wm; this.principals = null; this.roles = null; this.bean = bean; this.username = username; this.role = role; } public List<WorkContext> getWorkContexts() { List<WorkContext> l = new ArrayList<>(1); l.add(new MySecurityContext(username, role)); return l; } public void run() { bean.test(); SecurityIntegration securityIntegration = ((org.jboss.jca.core.api.workmanager.WorkManager) wm).getSecurityIntegration(); org.jboss.jca.core.spi.security.SecurityContext securityContext = securityIntegration.getSecurityContext(); if (securityContext != null) { Subject subject = securityContext.getAuthenticatedSubject(); if (subject != null) { if (subject.getPrincipals() != null && subject.getPrincipals().size() > 0) { principals = subject.getPrincipals(); } roles = securityContext.getRoles(); } } } public void release() { } public Set<Principal> getPrincipals() { return principals; } public String[] getRoles() { return roles; } } public static class MySecurityContext extends SecurityContext { private static final long serialVersionUID = 1L; private final String username; private final String role; public MySecurityContext(String username, String role) { super(); this.username = username; this.role = role; } public void setupSecurityContext(CallbackHandler handler, Subject executionSubject, Subject serviceSubject) { try { List<javax.security.auth.callback.Callback> cbs = new ArrayList<>(); cbs.add(new CallerPrincipalCallback(executionSubject, new SimplePrincipal(username))); cbs.add(new GroupPrincipalCallback(executionSubject, new String[]{role})); handler.handle(cbs.toArray(new javax.security.auth.callback.Callback[cbs.size()])); } catch (Throwable t) { throw new RuntimeException(t); } } } }
15,142
41.898017
162
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/annorar/AnnoAdminObject1.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.annorar; import java.io.Serializable; import jakarta.resource.Referenceable; /** * AnnoAdminObject * * @version $Revision: $ */ public interface AnnoAdminObject1 extends Referenceable, Serializable { /** * Set first * * @param first The value */ void setFirst(Float first); /** * Get first * * @return The value */ Float getFirst(); /** * Set second * * @param second The value */ void setSecond(String second); /** * Get second * * @return The value */ String getSecond(); }
1,673
25.571429
71
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/annorar/AnnoActivationSpec.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.annorar; import org.jboss.logging.Logger; import jakarta.resource.spi.Activation; import jakarta.resource.spi.ActivationSpec; import jakarta.resource.spi.ConfigProperty; import jakarta.resource.spi.InvalidPropertyException; import jakarta.resource.spi.ResourceAdapter; import jakarta.validation.constraints.NotNull; /** * AnnoActivationSpec * * @version $Revision: $ */ @Activation(messageListeners = {AnnoMessageListener.class, AnnoMessageListener1.class}) public class AnnoActivationSpec implements ActivationSpec { /** * The logger */ private static Logger log = Logger.getLogger("AnnoActivationSpec"); /** * The resource adapter */ private ResourceAdapter ra; /** * first */ @ConfigProperty(defaultValue = "C", description = {"1st", "first"}, ignore = true, supportsDynamicUpdates = false, confidential = true) @NotNull private Character first; /** * second */ private Double second; /** * Default constructor */ public AnnoActivationSpec() { } /** * Set first * * @param first The value */ public void setFirst(Character first) { this.first = first; } /** * Get first * * @return The value */ public Character getFirst() { return first; } /** * Set second * * @param second The value */ @ConfigProperty(defaultValue = "0.5", description = {"2nd", "second"}, ignore = false, supportsDynamicUpdates = true, confidential = false) public void setSecond(Double second) { this.second = second; } /** * Get second * * @return The value */ public Double getSecond() { return second; } /** * This method may be called by a deployment tool to validate the overall * activation configuration information provided by the endpoint deployer. * * @throws InvalidPropertyException indicates invalid configuration property settings. */ public void validate() throws InvalidPropertyException { log.trace("validate()"); } /** * Get the resource adapter * * @return The handle */ public ResourceAdapter getResourceAdapter() { log.trace("getResourceAdapter()"); return ra; } /** * Set the resource adapter * * @param ra The handle */ public void setResourceAdapter(ResourceAdapter ra) { log.trace("setResourceAdapter()"); this.ra = ra; } }
3,633
25.333333
143
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/annorar/AnnoConnectionImpl.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.annorar; import org.jboss.logging.Logger; /** * AnnoConnectionImpl * * @version $Revision: $ */ public class AnnoConnectionImpl implements AnnoConnection { /** * The logger */ private static Logger log = Logger.getLogger("AnnoConnectionImpl"); /** * ManagedConnection */ private AnnoManagedConnection mc; /** * ManagedConnectionFactory */ private AnnoManagedConnectionFactory mcf; /** * Default constructor * * @param mc AnnoManagedConnection * @param mcf AnnoManagedConnectionFactory */ public AnnoConnectionImpl(AnnoManagedConnection mc, AnnoManagedConnectionFactory mcf) { this.mc = mc; this.mcf = mcf; } /** * Call me */ public void callMe() { mc.callMe(); } /** * Close */ public void close() { mc.closeHandle(this); } /** * Returns AnnoManagedConnectionFactory * * @return mcf */ public AnnoManagedConnectionFactory getMCF() { return mcf; } }
2,174
25.204819
71
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/annorar/AnnoManagedConnectionFactory1.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.annorar; import java.io.PrintWriter; import java.util.Iterator; import java.util.Set; import org.jboss.logging.Logger; import jakarta.resource.ResourceException; import jakarta.resource.spi.ConfigProperty; import jakarta.resource.spi.ConnectionDefinition; import jakarta.resource.spi.ConnectionManager; import jakarta.resource.spi.ConnectionRequestInfo; import jakarta.resource.spi.ManagedConnection; import jakarta.resource.spi.ManagedConnectionFactory; import jakarta.resource.spi.ResourceAdapter; import jakarta.resource.spi.ResourceAdapterAssociation; import javax.security.auth.Subject; /** * AnnoManagedConnectionFactory * * @version $Revision: $ */ @ConnectionDefinition(connectionFactory = AnnoConnectionFactory1.class, connectionFactoryImpl = AnnoConnectionFactoryImpl1.class, connection = AnnoConnection1.class, connectionImpl = AnnoConnectionImpl1.class) public class AnnoManagedConnectionFactory1 implements ManagedConnectionFactory, ResourceAdapterAssociation { /** * The serial version UID */ private static final long serialVersionUID = 1L; /** * The logger */ private static Logger log = Logger .getLogger("AnnoManagedConnectionFactory"); /** * The resource adapter */ private ResourceAdapter ra; /** * The logwriter */ private PrintWriter logwriter; /** * first */ @ConfigProperty(defaultValue = "2", description = {"1st", "first"}, ignore = true, supportsDynamicUpdates = false, confidential = true) private Byte first; /** * second */ private Short second; /** * Default constructor */ public AnnoManagedConnectionFactory1() { } /** * Set first * * @param first The value */ public void setFirst(Byte first) { this.first = first; } /** * Get first * * @return The value */ public Byte getFirst() { return first; } /** * Set second * * @param second The value */ @ConfigProperty(defaultValue = "1", description = {"2nd", "second"}, ignore = false, supportsDynamicUpdates = true, confidential = false) public void setSecond(Short second) { this.second = second; } /** * Get second * * @return The value */ public Short getSecond() { return second; } /** * Creates a Connection Factory instance. * * @param cxManager ConnectionManager to be associated with created EIS connection * factory instance * @return EIS-specific Connection Factory instance or * jakarta.resource.cci.ConnectionFactory instance * @throws ResourceException Generic exception */ public Object createConnectionFactory(ConnectionManager cxManager) throws ResourceException { log.trace("createConnectionFactory()"); return new AnnoConnectionFactoryImpl1(this, cxManager); } /** * Creates a Connection Factory instance. * * @return EIS-specific Connection Factory instance or * jakarta.resource.cci.ConnectionFactory instance * @throws ResourceException Generic exception */ public Object createConnectionFactory() throws ResourceException { throw new ResourceException( "This resource adapter doesn't support non-managed environments"); } /** * Creates a new physical connection to the underlying EIS resource manager. * * @param subject Caller's security information * @param cxRequestInfo Additional resource adapter specific connection request * information * @return ManagedConnection instance * @throws ResourceException generic exception */ public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException { log.trace("createManagedConnection()"); return new AnnoManagedConnection1(this); } /** * Returns a matched connection from the candidate set of connections. * * @param connectionSet Candidate connection set * @param subject Caller's security information * @param cxRequestInfo Additional resource adapter specific connection request * information * @return ManagedConnection if resource adapter finds an acceptable match * otherwise null * @throws ResourceException generic exception */ public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException { log.trace("matchManagedConnections()"); ManagedConnection result = null; Iterator it = connectionSet.iterator(); while (result == null && it.hasNext()) { ManagedConnection mc = (ManagedConnection) it.next(); if (mc instanceof AnnoManagedConnection1) { result = mc; } } return result; } /** * Get the log writer for this ManagedConnectionFactory instance. * * @return PrintWriter * @throws ResourceException generic exception */ public PrintWriter getLogWriter() throws ResourceException { log.trace("getLogWriter()"); return logwriter; } /** * Set the log writer for this ManagedConnectionFactory instance. * * @param out PrintWriter - an out stream for error logging and tracing * @throws ResourceException generic exception */ public void setLogWriter(PrintWriter out) throws ResourceException { log.trace("setLogWriter()"); logwriter = out; } /** * Get the resource adapter * * @return The handle */ public ResourceAdapter getResourceAdapter() { log.trace("getResourceAdapter()"); return ra; } /** * Set the resource adapter * * @param ra The handle */ public void setResourceAdapter(ResourceAdapter ra) { log.trace("setResourceAdapter()"); this.ra = ra; } /** * Returns a hash code value for the object. * * @return A hash code value for this object. */ @Override public int hashCode() { int result = 17; if (first != null) { result += 31 * result + 7 * first.hashCode(); } else { result += 31 * result + 7; } if (second != null) { result += 31 * result + 7 * second.hashCode(); } else { result += 31 * result + 7; } return result; } /** * Indicates whether some other object is equal to this one. * * @param other The reference object with which to compare. * @return true if this object is the same as the obj argument, false * otherwise. */ @Override public boolean equals(Object other) { if (other == null) { return false; } if (other == this) { return true; } if (!(other instanceof AnnoManagedConnectionFactory1)) { return false; } boolean result = true; AnnoManagedConnectionFactory1 obj = (AnnoManagedConnectionFactory1) other; if (result) { if (first == null) { result = obj.getFirst() == null; } else { result = first.equals(obj.getFirst()); } } if (result) { if (second == null) { result = obj.getSecond() == null; } else { result = second.equals(obj.getSecond()); } } return result; } }
8,709
31.022059
209
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/annorar/AnnoMessageListener.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.annorar; /** * AnnoMessageListener * * @version $Revision: $ */ public interface AnnoMessageListener { /** * Receive message * * @param msg String. */ void onMessage(String msg); }
1,288
33.837838
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/annorar/AnnoConnectionFactory1.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.annorar; import java.io.Serializable; import jakarta.resource.Referenceable; import jakarta.resource.ResourceException; /** * AnnoConnectionFactory * * @version $Revision: $ */ public interface AnnoConnectionFactory1 extends Serializable, Referenceable { /** * Get connection from factory * * @return AnnoConnection instance * @throws ResourceException Thrown if a connection can't be obtained */ AnnoConnection1 getConnection() throws ResourceException; }
1,571
35.55814
77
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/annorar/AnnoConnection.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.annorar; /** * AnnoConnection * * @version $Revision: $ */ public interface AnnoConnection { /** * Call me */ void callMe(); /** * Close */ void close(); }
1,272
30.825
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/annorar/AnnoActivation.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.annorar; import jakarta.resource.ResourceException; import jakarta.resource.spi.endpoint.MessageEndpointFactory; /** * AnnoActivation * * @version $Revision: $ */ public class AnnoActivation { /** * The resource adapter */ private AnnoResourceAdapter ra; /** * Activation spec */ private AnnoActivationSpec spec; /** * The message endpoint factory */ private MessageEndpointFactory endpointFactory; /** * Default constructor * * @throws ResourceException Thrown if an error occurs */ public AnnoActivation() throws ResourceException { this(null, null, null); } /** * Constructor * * @param ra AnnoResourceAdapter * @param endpointFactory MessageEndpointFactory * @param spec AnnoActivationSpec * @throws ResourceException Thrown if an error occurs */ public AnnoActivation(AnnoResourceAdapter ra, MessageEndpointFactory endpointFactory, AnnoActivationSpec spec) throws ResourceException { this.ra = ra; this.endpointFactory = endpointFactory; this.spec = spec; } /** * Get activation spec class * * @return Activation spec */ public AnnoActivationSpec getActivationSpec() { return spec; } /** * Get message endpoint factory * * @return Message endpoint factory */ public MessageEndpointFactory getMessageEndpointFactory() { return endpointFactory; } /** * Start the activation * * @throws ResourceException Thrown if an error occurs */ public void start() throws ResourceException { } /** * Stop the activation */ public void stop() { } }
2,892
25.541284
90
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/annorar/AnnoManagedConnection1.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.annorar; import static org.wildfly.common.Assert.checkNotNullParam; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.jboss.logging.Logger; import jakarta.resource.ResourceException; import jakarta.resource.spi.ConnectionEvent; import jakarta.resource.spi.ConnectionEventListener; import jakarta.resource.spi.ConnectionRequestInfo; import jakarta.resource.spi.LocalTransaction; import jakarta.resource.spi.ManagedConnection; import jakarta.resource.spi.ManagedConnectionMetaData; import javax.security.auth.Subject; import javax.transaction.xa.XAResource; /** * AnnoManagedConnection * * @version $Revision: $ */ public class AnnoManagedConnection1 implements ManagedConnection { /** * The logger */ private static Logger log = Logger.getLogger("AnnoManagedConnection"); /** * The logwriter */ private PrintWriter logwriter; /** * ManagedConnectionFactory */ private AnnoManagedConnectionFactory1 mcf; /** * Listeners */ private List<ConnectionEventListener> listeners; /** * Connection */ private AnnoConnectionImpl1 connection; /** * Default constructor * * @param mcf mcf */ public AnnoManagedConnection1(AnnoManagedConnectionFactory1 mcf) { this.mcf = mcf; this.logwriter = null; this.listeners = Collections .synchronizedList(new ArrayList<ConnectionEventListener>(1)); this.connection = null; } /** * Creates a new connection handle for the underlying physical connection * represented by the ManagedConnection instance. * * @param subject Security context as JAAS subject * @param cxRequestInfo ConnectionRequestInfo instance * @return generic Object instance representing the connection handle. * @throws ResourceException generic exception if operation fails */ public Object getConnection(Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException { log.trace("getConnection()"); connection = new AnnoConnectionImpl1(this, mcf); return connection; } /** * Used by the container to change the association of an application-level * connection handle with a ManagedConneciton instance. * * @param connection Application-level connection handle * @throws ResourceException generic exception if operation fails */ public void associateConnection(Object connection) throws ResourceException { log.trace("associateConnection()"); if (connection == null) { throw new ResourceException("Null connection handle"); } if (!(connection instanceof AnnoConnectionImpl)) { throw new ResourceException("Wrong connection handle"); } this.connection = (AnnoConnectionImpl1) connection; } /** * Application server calls this method to force any cleanup on the * ManagedConnection instance. * * @throws ResourceException generic exception if operation fails */ public void cleanup() throws ResourceException { log.trace("cleanup()"); } /** * Destroys the physical connection to the underlying resource manager. * * @throws ResourceException generic exception if operation fails */ public void destroy() throws ResourceException { log.trace("destroy()"); } /** * Adds a connection event listener to the ManagedConnection instance. * * @param listener A new ConnectionEventListener to be registered */ public void addConnectionEventListener(ConnectionEventListener listener) { log.trace("addConnectionEventListener()"); checkNotNullParam("listener", listener); listeners.add(listener); } /** * Removes an already registered connection event listener from the * ManagedConnection instance. * * @param listener already registered connection event listener to be removed */ public void removeConnectionEventListener(ConnectionEventListener listener) { log.trace("removeConnectionEventListener()"); checkNotNullParam("listener", listener); listeners.remove(listener); } /** * Close handle * * @param handle The handle */ void closeHandle(AnnoConnection1 handle) { ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED); event.setConnectionHandle(handle); for (ConnectionEventListener cel : listeners) { cel.connectionClosed(event); } } /** * Gets the log writer for this ManagedConnection instance. * * @return Character output stream associated with this Managed-Connection * instance * @throws ResourceException generic exception if operation fails */ public PrintWriter getLogWriter() throws ResourceException { log.trace("getLogWriter()"); return logwriter; } /** * Sets the log writer for this ManagedConnection instance. * * @param out Character Output stream to be associated * @throws ResourceException generic exception if operation fails */ public void setLogWriter(PrintWriter out) throws ResourceException { log.trace("setLogWriter()"); logwriter = out; } /** * Returns an <code>jakarta.resource.spi.LocalTransaction</code> instance. * * @return LocalTransaction instance * @throws ResourceException generic exception if operation fails */ public LocalTransaction getLocalTransaction() throws ResourceException { log.trace("getLocalTransaction()"); return null; } /** * Returns an <code>javax.transaction.xa.XAresource</code> instance. * * @return XAResource instance * @throws ResourceException generic exception if operation fails */ public XAResource getXAResource() throws ResourceException { log.trace("getXAResource()"); return null; } /** * Gets the metadata information for this connection's underlying EIS * resource manager instance. * * @return ManagedConnectionMetaData instance * @throws ResourceException generic exception if operation fails */ public ManagedConnectionMetaData getMetaData() throws ResourceException { log.trace("getMetaData()"); return new AnnoManagedConnectionMetaData(); } /** * Call me */ void callMe() { log.trace("callMe()"); } }
7,744
31.136929
116
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/annorar/AnnoRaMetaData.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.annorar; import jakarta.resource.cci.ResourceAdapterMetaData; /** * AnnoRaMetaData * * @version $Revision: $ */ public class AnnoRaMetaData implements ResourceAdapterMetaData { /** * Default constructor */ public AnnoRaMetaData() { } /** * Gets the version of the resource adapter. * * @return String representing version of the resource adapter */ @Override public String getAdapterVersion() { return null; // TODO } /** * Gets the name of the vendor that has provided the resource adapter. * * @return String representing name of the vendor */ @Override public String getAdapterVendorName() { return null; // TODO } /** * Gets a tool displayable name of the resource adapter. * * @return String representing the name of the resource adapter */ @Override public String getAdapterName() { return null; // TODO } /** * Gets a tool displayable short desription of the resource adapter. * * @return String describing the resource adapter */ @Override public String getAdapterShortDescription() { return null; // TODO } /** * Returns a string representation of the version * * @return String representing the supported version of the connector * architecture */ @Override public String getSpecVersion() { return null; // TODO } /** * Returns an array of fully-qualified names of InteractionSpec * * @return Array of fully-qualified class names of InteractionSpec classes */ @Override public String[] getInteractionSpecsSupported() { return null; // TODO } /** * Returns true if the implementation class for the Interaction * * @return boolean Depending on method support */ @Override public boolean supportsExecuteWithInputAndOutputRecord() { return false; // TODO } /** * Returns true if the implementation class for the Interaction * * @return boolean Depending on method support */ @Override public boolean supportsExecuteWithInputRecordOnly() { return false; // TODO } /** * Returns true if the resource adapter implements the LocalTransaction * * @return true If resource adapter supports resource manager local * transaction demarcation */ @Override public boolean supportsLocalTransactionDemarcation() { return false; // TODO } }
3,652
26.674242
78
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/annorar/AnnoMessageListener1.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.annorar; /** * AnnoMessageListener * * @version $Revision: $ */ public interface AnnoMessageListener1 { /** * Receive message * * @param msg String. */ void onMessage(String msg); }
1,289
33.864865
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/annorar/AnnoConnectionImpl1.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.annorar; import org.jboss.logging.Logger; /** * AnnoConnectionImpl * * @version $Revision: $ */ public class AnnoConnectionImpl1 implements AnnoConnection1 { /** * The logger */ private static Logger log = Logger.getLogger("AnnoConnectionImpl"); /** * ManagedConnection */ private AnnoManagedConnection1 mc; /** * ManagedConnectionFactory */ private AnnoManagedConnectionFactory1 mcf; /** * Default constructor * * @param mc AnnoManagedConnection * @param mcf AnnoManagedConnectionFactory */ public AnnoConnectionImpl1(AnnoManagedConnection1 mc, AnnoManagedConnectionFactory1 mcf) { this.mc = mc; this.mcf = mcf; } /** * Call me */ public void callMe() { mc.callMe(); } /** * Close */ public void close() { mc.closeHandle(this); } /** * Returns AnnoManagedConnectionFactory * * @return mcf */ public AnnoManagedConnectionFactory1 getMCF() { return mcf; } }
2,183
25.313253
71
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/annorar/AnnoResourceAdapter.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.annorar; import java.util.concurrent.ConcurrentHashMap; import org.jboss.logging.Logger; import jakarta.resource.ResourceException; import jakarta.resource.spi.ActivationSpec; import jakarta.resource.spi.AuthenticationMechanism; import jakarta.resource.spi.AuthenticationMechanism.CredentialInterface; import jakarta.resource.spi.BootstrapContext; import jakarta.resource.spi.ConfigProperty; import jakarta.resource.spi.Connector; import jakarta.resource.spi.ResourceAdapter; import jakarta.resource.spi.ResourceAdapterInternalException; import jakarta.resource.spi.SecurityPermission; import jakarta.resource.spi.TransactionSupport; import jakarta.resource.spi.endpoint.MessageEndpointFactory; import jakarta.resource.spi.work.HintsContext; import jakarta.resource.spi.work.TransactionContext; import javax.transaction.xa.XAResource; /** * AnnoResourceAdapter * * @version $Revision: $ */ @Connector(description = {"first", "second"}, displayName = {"disp1", "disp2"}, smallIcon = {"s1", "", "s3", ""}, largeIcon = {"l1", "l2", "", ""}, vendorName = "vendor", eisType = "type", version = "1.a", licenseRequired = true, licenseDescription = { "lic1", "lic2"}, reauthenticationSupport = true, transactionSupport = TransactionSupport.TransactionSupportLevel.LocalTransaction, authMechanisms = { @AuthenticationMechanism(credentialInterface = CredentialInterface.PasswordCredential), @AuthenticationMechanism(credentialInterface = CredentialInterface.GenericCredential, authMechanism = "AuthMechanism", description = { "desc1", "desc2"})}, securityPermissions = { @SecurityPermission(permissionSpec = "spec1"), @SecurityPermission(permissionSpec = "spec2", description = {"d1", "d2"})}, requiredWorkContexts = {TransactionContext.class, HintsContext.class}) public class AnnoResourceAdapter implements ResourceAdapter, java.io.Serializable { /** * The serial version UID */ private static final long serialVersionUID = 1L; /** * The logger */ private static Logger log = Logger.getLogger("AnnoResourceAdapter"); /** * The activations by activation spec */ private ConcurrentHashMap<AnnoActivationSpec, AnnoActivation> activations; /** * first */ @ConfigProperty(defaultValue = "A", description = {"1st", "first"}, ignore = true, supportsDynamicUpdates = false, confidential = true) private String first; /** * second */ private Integer second; /** * Default constructor */ public AnnoResourceAdapter() { this.activations = new ConcurrentHashMap<AnnoActivationSpec, AnnoActivation>(); } /** * Set first * * @param first The value */ public void setFirst(String first) { this.first = first; } /** * Get first * * @return The value */ public String getFirst() { return first; } /** * Set second * * @param second The value */ @ConfigProperty(defaultValue = "5", description = {"2nd", "second"}, ignore = false, supportsDynamicUpdates = true, confidential = false) public void setSecond(Integer second) { this.second = second; } /** * Get second * * @return The value */ public Integer getSecond() { return second; } /** * This is called during the activation of a message endpoint. * * @param endpointFactory A message endpoint factory instance. * @param spec An activation spec JavaBean instance. * @throws ResourceException generic exception */ public void endpointActivation(MessageEndpointFactory endpointFactory, ActivationSpec spec) throws ResourceException { AnnoActivation activation = new AnnoActivation(this, endpointFactory, (AnnoActivationSpec) spec); activations.put((AnnoActivationSpec) spec, activation); activation.start(); log.trace("endpointActivation()"); } /** * This is called when a message endpoint is deactivated. * * @param endpointFactory A message endpoint factory instance. * @param spec An activation spec JavaBean instance. */ public void endpointDeactivation(MessageEndpointFactory endpointFactory, ActivationSpec spec) { AnnoActivation activation = activations.remove(spec); if (activation != null) { activation.stop(); } log.trace("endpointDeactivation()"); } /** * This is called when a resource adapter instance is bootstrapped. * * @param ctx A bootstrap context containing references * @throws ResourceAdapterInternalException indicates bootstrap failure. */ public void start(BootstrapContext ctx) throws ResourceAdapterInternalException { log.trace("start()"); } /** * This is called when a resource adapter instance is undeployed or during * application server shutdown. */ public void stop() { log.trace("stop()"); } /** * This method is called by the application server during crash recovery. * * @param specs An array of ActivationSpec JavaBeans * @return An array of XAResource objects * @throws ResourceException generic exception */ public XAResource[] getXAResources(ActivationSpec[] specs) throws ResourceException { log.trace("getXAResources()"); return null; } /** * Returns a hash code value for the object. * * @return A hash code value for this object. */ @Override public int hashCode() { int result = 17; if (first != null) { result += 31 * result + 7 * first.hashCode(); } else { result += 31 * result + 7; } if (second != null) { result += 31 * result + 7 * second.hashCode(); } else { result += 31 * result + 7; } return result; } /** * Indicates whether some other object is equal to this one. * * @param other The reference object with which to compare. * @return true if this object is the same as the obj argument, false * otherwise. */ @Override public boolean equals(Object other) { if (other == null) { return false; } if (other == this) { return true; } if (!(other instanceof AnnoResourceAdapter)) { return false; } boolean result = true; AnnoResourceAdapter obj = (AnnoResourceAdapter) other; if (result) { if (first == null) { result = obj.getFirst() == null; } else { result = first.equals(obj.getFirst()); } } if (result) { if (second == null) { result = obj.getSecond() == null; } else { result = second.equals(obj.getSecond()); } } return result; } }
8,036
33.642241
157
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/annorar/AnnoAdminObjectImpl1.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.annorar; import javax.naming.NamingException; import javax.naming.Reference; import jakarta.resource.spi.AdministeredObject; import jakarta.resource.spi.ConfigProperty; import jakarta.resource.spi.ResourceAdapter; import jakarta.resource.spi.ResourceAdapterAssociation; /** * AnnoAdminObjectImpl * * @version $Revision: $ */ @AdministeredObject(adminObjectInterfaces = {AnnoAdminObject1.class}) public class AnnoAdminObjectImpl1 implements AnnoAdminObject1, ResourceAdapterAssociation { /** * Serial version uid */ private static final long serialVersionUID = 1L; /** * The resource adapter */ private ResourceAdapter ra; /** * Reference */ private Reference reference; /** * first */ @ConfigProperty(defaultValue = "3.14", description = {"1st", "first"}, ignore = true, supportsDynamicUpdates = false, confidential = true) private Float first; /** * second */ private String second; /** * Default constructor */ public AnnoAdminObjectImpl1() { } /** * Set first * * @param first The value */ public void setFirst(Float first) { this.first = first; } /** * Get first * * @return The value */ public Float getFirst() { return first; } /** * Set second * * @param second The value */ @ConfigProperty(defaultValue = "B", description = {"2nd", "second"}, ignore = false, supportsDynamicUpdates = true, confidential = false) public void setSecond(String second) { this.second = second; } /** * Get second * * @return The value */ public String getSecond() { return second; } /** * Get the resource adapter * * @return The handle */ public ResourceAdapter getResourceAdapter() { return ra; } /** * Set the resource adapter * * @param ra The handle */ public void setResourceAdapter(ResourceAdapter ra) { this.ra = ra; } /** * Get the Reference instance. * * @return Reference instance * @throws NamingException Thrown if a reference can't be obtained */ @Override public Reference getReference() throws NamingException { return reference; } /** * Set the Reference instance. * * @param reference A Reference instance */ @Override public void setReference(Reference reference) { this.reference = reference; } /** * Returns a hash code value for the object. * * @return A hash code value for this object. */ @Override public int hashCode() { int result = 17; if (first != null) { result += 31 * result + 7 * first.hashCode(); } else { result += 31 * result + 7; } if (second != null) { result += 31 * result + 7 * second.hashCode(); } else { result += 31 * result + 7; } return result; } /** * Indicates whether some other object is equal to this one. * * @param other The reference object with which to compare. * @return true if this object is the same as the obj argument, false * otherwise. */ @Override public boolean equals(Object other) { if (other == null) { return false; } if (other == this) { return true; } if (!(other instanceof AnnoAdminObjectImpl1)) { return false; } boolean result = true; AnnoAdminObjectImpl1 obj = (AnnoAdminObjectImpl1) other; if (result) { if (first == null) { result = obj.getFirst() == null; } else { result = first.equals(obj.getFirst()); } } if (result) { if (second == null) { result = obj.getSecond() == null; } else { result = second.equals(obj.getSecond()); } } return result; } }
4,994
26
142
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/annorar/AnnoManagedConnectionMetaData.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.annorar; import org.jboss.logging.Logger; import jakarta.resource.ResourceException; import jakarta.resource.spi.ManagedConnectionMetaData; /** * AnnoManagedConnectionMetaData * * @version $Revision: $ */ public class AnnoManagedConnectionMetaData implements ManagedConnectionMetaData { /** * The logger */ private static Logger log = Logger .getLogger("AnnoManagedConnectionMetaData"); /** * Default constructor */ public AnnoManagedConnectionMetaData() { } /** * Returns Product name of the underlying EIS instance connected through the * ManagedConnection. * * @return Product name of the EIS instance * @throws ResourceException Thrown if an error occurs */ @Override public String getEISProductName() throws ResourceException { log.trace("getEISProductName()"); return null; // TODO } /** * Returns Product version of the underlying EIS instance connected through * the ManagedConnection. * * @return Product version of the EIS instance * @throws ResourceException Thrown if an error occurs */ @Override public String getEISProductVersion() throws ResourceException { log.trace("getEISProductVersion()"); return null; // TODO } /** * Returns maximum limit on number of active concurrent connections * * @return Maximum limit for number of active concurrent connections * @throws ResourceException Thrown if an error occurs */ @Override public int getMaxConnections() throws ResourceException { log.trace("getMaxConnections()"); return 0; // TODO } /** * Returns name of the user associated with the ManagedConnection instance * * @return Name of the user * @throws ResourceException Thrown if an error occurs */ @Override public String getUserName() throws ResourceException { log.trace("getUserName()"); return null; // TODO } }
3,112
30.765306
81
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/annorar/AnnoAdminObject.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.annorar; import java.io.Serializable; import jakarta.resource.Referenceable; /** * AnnoAdminObject * * @version $Revision: $ */ public interface AnnoAdminObject extends Referenceable, Serializable { /** * Set first * * @param first The value */ void setFirst(Long first); /** * Get first * * @return The value */ Long getFirst(); /** * Set second * * @param second The value */ void setSecond(Boolean second); /** * Get second * * @return The value */ Boolean getSecond(); }
1,672
25.555556
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/annorar/AnnoManagedConnectionFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.annorar; import java.io.PrintWriter; import java.util.Iterator; import java.util.Set; import org.jboss.logging.Logger; import jakarta.resource.ResourceException; import jakarta.resource.spi.ConfigProperty; import jakarta.resource.spi.ConnectionDefinition; import jakarta.resource.spi.ConnectionManager; import jakarta.resource.spi.ConnectionRequestInfo; import jakarta.resource.spi.ManagedConnection; import jakarta.resource.spi.ManagedConnectionFactory; import jakarta.resource.spi.ResourceAdapter; import jakarta.resource.spi.ResourceAdapterAssociation; import javax.security.auth.Subject; /** * AnnoManagedConnectionFactory * * @version $Revision: $ */ @ConnectionDefinition(connectionFactory = AnnoConnectionFactory.class, connectionFactoryImpl = AnnoConnectionFactoryImpl.class, connection = AnnoConnection.class, connectionImpl = AnnoConnectionImpl.class) public class AnnoManagedConnectionFactory implements ManagedConnectionFactory, ResourceAdapterAssociation { /** * The serial version UID */ private static final long serialVersionUID = 1L; /** * The logger */ private static Logger log = Logger .getLogger("AnnoManagedConnectionFactory"); /** * The resource adapter */ private ResourceAdapter ra; /** * The logwriter */ private PrintWriter logwriter; /** * first */ @ConfigProperty(defaultValue = "4", description = {"1st", "first"}, ignore = true, supportsDynamicUpdates = false, confidential = true) private Byte first; /** * second */ private Short second; /** * Default constructor */ public AnnoManagedConnectionFactory() { } /** * Set first * * @param first The value */ public void setFirst(Byte first) { this.first = first; } /** * Get first * * @return The value */ public Byte getFirst() { return first; } /** * Set second * * @param second The value */ @ConfigProperty(defaultValue = "0", description = {"2nd", "second"}, ignore = false, supportsDynamicUpdates = true, confidential = false) public void setSecond(Short second) { this.second = second; } /** * Get second * * @return The value */ public Short getSecond() { return second; } /** * Creates a Connection Factory instance. * * @param cxManager ConnectionManager to be associated with created EIS connection * factory instance * @return EIS-specific Connection Factory instance or * jakarta.resource.cci.ConnectionFactory instance * @throws ResourceException Generic exception */ public Object createConnectionFactory(ConnectionManager cxManager) throws ResourceException { log.trace("createConnectionFactory()"); return new AnnoConnectionFactoryImpl(this, cxManager); } /** * Creates a Connection Factory instance. * * @return EIS-specific Connection Factory instance or * jakarta.resource.cci.ConnectionFactory instance * @throws ResourceException Generic exception */ public Object createConnectionFactory() throws ResourceException { throw new ResourceException( "This resource adapter doesn't support non-managed environments"); } /** * Creates a new physical connection to the underlying EIS resource manager. * * @param subject Caller's security information * @param cxRequestInfo Additional resource adapter specific connection request * information * @return ManagedConnection instance * @throws ResourceException generic exception */ public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException { log.trace("createManagedConnection()"); return new AnnoManagedConnection(this); } /** * Returns a matched connection from the candidate set of connections. * * @param connectionSet Candidate connection set * @param subject Caller's security information * @param cxRequestInfo Additional resource adapter specific connection request * information * @return ManagedConnection if resource adapter finds an acceptable match * otherwise null * @throws ResourceException generic exception */ public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException { log.trace("matchManagedConnections()"); ManagedConnection result = null; Iterator it = connectionSet.iterator(); while (result == null && it.hasNext()) { ManagedConnection mc = (ManagedConnection) it.next(); if (mc instanceof AnnoManagedConnection) { result = mc; } } return result; } /** * Get the log writer for this ManagedConnectionFactory instance. * * @return PrintWriter * @throws ResourceException generic exception */ public PrintWriter getLogWriter() throws ResourceException { log.trace("getLogWriter()"); return logwriter; } /** * Set the log writer for this ManagedConnectionFactory instance. * * @param out PrintWriter - an out stream for error logging and tracing * @throws ResourceException generic exception */ public void setLogWriter(PrintWriter out) throws ResourceException { log.trace("setLogWriter()"); logwriter = out; } /** * Get the resource adapter * * @return The handle */ public ResourceAdapter getResourceAdapter() { log.trace("getResourceAdapter()"); return ra; } /** * Set the resource adapter * * @param ra The handle */ public void setResourceAdapter(ResourceAdapter ra) { log.trace("setResourceAdapter()"); this.ra = ra; } /** * Returns a hash code value for the object. * * @return A hash code value for this object. */ @Override public int hashCode() { int result = 17; if (first != null) { result += 31 * result + 7 * first.hashCode(); } else { result += 31 * result + 7; } if (second != null) { result += 31 * result + 7 * second.hashCode(); } else { result += 31 * result + 7; } return result; } /** * Indicates whether some other object is equal to this one. * * @param other The reference object with which to compare. * @return true if this object is the same as the obj argument, false * otherwise. */ @Override public boolean equals(Object other) { if (other == null) { return false; } if (other == this) { return true; } if (!(other instanceof AnnoManagedConnectionFactory)) { return false; } boolean result = true; AnnoManagedConnectionFactory obj = (AnnoManagedConnectionFactory) other; if (result) { if (first == null) { result = obj.getFirst() == null; } else { result = first.equals(obj.getFirst()); } } if (result) { if (second == null) { result = obj.getSecond() == null; } else { result = second.equals(obj.getSecond()); } } return result; } }
8,697
30.977941
205
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/annorar/AnnoManagedConnection.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.annorar; import static org.wildfly.common.Assert.checkNotNullParam; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.jboss.logging.Logger; import jakarta.resource.ResourceException; import jakarta.resource.spi.ConnectionEvent; import jakarta.resource.spi.ConnectionEventListener; import jakarta.resource.spi.ConnectionRequestInfo; import jakarta.resource.spi.LocalTransaction; import jakarta.resource.spi.ManagedConnection; import jakarta.resource.spi.ManagedConnectionMetaData; import javax.security.auth.Subject; import javax.transaction.xa.XAResource; /** * AnnoManagedConnection * * @version $Revision: $ */ public class AnnoManagedConnection implements ManagedConnection { /** * The logger */ private static Logger log = Logger.getLogger("AnnoManagedConnection"); /** * The logwriter */ private PrintWriter logwriter; /** * ManagedConnectionFactory */ private AnnoManagedConnectionFactory mcf; /** * Listeners */ private List<ConnectionEventListener> listeners; /** * Connection */ private AnnoConnectionImpl connection; /** * Default constructor * * @param mcf mcf */ public AnnoManagedConnection(AnnoManagedConnectionFactory mcf) { this.mcf = mcf; this.logwriter = null; this.listeners = Collections .synchronizedList(new ArrayList<ConnectionEventListener>(1)); this.connection = null; } /** * Creates a new connection handle for the underlying physical connection * represented by the ManagedConnection instance. * * @param subject Security context as JAAS subject * @param cxRequestInfo ConnectionRequestInfo instance * @return generic Object instance representing the connection handle. * @throws ResourceException generic exception if operation fails */ public Object getConnection(Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException { log.trace("getConnection()"); connection = new AnnoConnectionImpl(this, mcf); return connection; } /** * Used by the container to change the association of an application-level * connection handle with a ManagedConneciton instance. * * @param connection Application-level connection handle * @throws ResourceException generic exception if operation fails */ public void associateConnection(Object connection) throws ResourceException { log.trace("associateConnection()"); if (connection == null) { throw new ResourceException("Null connection handle"); } if (!(connection instanceof AnnoConnectionImpl)) { throw new ResourceException("Wrong connection handle"); } this.connection = (AnnoConnectionImpl) connection; } /** * Application server calls this method to force any cleanup on the * ManagedConnection instance. * * @throws ResourceException generic exception if operation fails */ public void cleanup() throws ResourceException { log.trace("cleanup()"); } /** * Destroys the physical connection to the underlying resource manager. * * @throws ResourceException generic exception if operation fails */ public void destroy() throws ResourceException { log.trace("destroy()"); } /** * Adds a connection event listener to the ManagedConnection instance. * * @param listener A new ConnectionEventListener to be registered */ public void addConnectionEventListener(ConnectionEventListener listener) { log.trace("addConnectionEventListener()"); checkNotNullParam("listener", listener); listeners.add(listener); } /** * Removes an already registered connection event listener from the * ManagedConnection instance. * * @param listener already registered connection event listener to be removed */ public void removeConnectionEventListener(ConnectionEventListener listener) { log.trace("removeConnectionEventListener()"); checkNotNullParam("listener", listener); listeners.remove(listener); } /** * Close handle * * @param handle The handle */ void closeHandle(AnnoConnection handle) { ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED); event.setConnectionHandle(handle); for (ConnectionEventListener cel : listeners) { cel.connectionClosed(event); } } /** * Gets the log writer for this ManagedConnection instance. * * @return Character output stream associated with this Managed-Connection * instance * @throws ResourceException generic exception if operation fails */ public PrintWriter getLogWriter() throws ResourceException { log.trace("getLogWriter()"); return logwriter; } /** * Sets the log writer for this ManagedConnection instance. * * @param out Character Output stream to be associated * @throws ResourceException generic exception if operation fails */ public void setLogWriter(PrintWriter out) throws ResourceException { log.trace("setLogWriter()"); logwriter = out; } /** * Returns an <code>jakarta.resource.spi.LocalTransaction</code> instance. * * @return LocalTransaction instance * @throws ResourceException generic exception if operation fails */ public LocalTransaction getLocalTransaction() throws ResourceException { log.trace("getLocalTransaction()"); return null; } /** * Returns an <code>javax.transaction.xa.XAresource</code> instance. * * @return XAResource instance * @throws ResourceException generic exception if operation fails */ public XAResource getXAResource() throws ResourceException { log.trace("getXAResource()"); return null; } /** * Gets the metadata information for this connection's underlying EIS * resource manager instance. * * @return ManagedConnectionMetaData instance * @throws ResourceException generic exception if operation fails */ public ManagedConnectionMetaData getMetaData() throws ResourceException { log.trace("getMetaData()"); return new AnnoManagedConnectionMetaData(); } /** * Call me */ void callMe() { log.trace("callMe()"); } }
7,736
31.103734
116
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/annorar/AnnoConnectionFactoryImpl1.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.annorar; import org.jboss.logging.Logger; import javax.naming.NamingException; import javax.naming.Reference; import jakarta.resource.ResourceException; import jakarta.resource.spi.ConnectionManager; /** * AnnoConnectionFactoryImpl * * @version $Revision: $ */ public class AnnoConnectionFactoryImpl1 implements AnnoConnectionFactory1 { /** * The serial version UID */ private static final long serialVersionUID = 1L; /** * The logger */ private static Logger log = Logger.getLogger("AnnoConnectionFactoryImpl"); /** * Reference */ private Reference reference; /** * ManagedConnectionFactory */ private AnnoManagedConnectionFactory1 mcf; /** * ConnectionManager */ private ConnectionManager connectionManager; /** * Default constructor */ public AnnoConnectionFactoryImpl1() { } /** * Default constructor * * @param mcf ManagedConnectionFactory * @param cxManager ConnectionManager */ public AnnoConnectionFactoryImpl1(AnnoManagedConnectionFactory1 mcf, ConnectionManager cxManager) { this.mcf = mcf; this.connectionManager = cxManager; } /** * Get connection from factory * * @return AnnoConnection instance * @throws ResourceException Thrown if a connection can't be obtained */ @Override public AnnoConnection1 getConnection() throws ResourceException { log.trace("getConnection()"); return (AnnoConnection1) connectionManager .allocateConnection(mcf, null); } /** * Get the Reference instance. * * @return Reference instance * @throws NamingException Thrown if a reference can't be obtained */ @Override public Reference getReference() throws NamingException { log.trace("getReference()"); return reference; } /** * Set the Reference instance. * * @param reference A Reference instance */ @Override public void setReference(Reference reference) { log.trace("setReference()"); this.reference = reference; } }
3,294
27.162393
78
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/annorar/AnnoAdminObjectImpl.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.annorar; import javax.naming.NamingException; import javax.naming.Reference; import jakarta.resource.spi.AdministeredObject; import jakarta.resource.spi.ConfigProperty; import jakarta.resource.spi.ResourceAdapter; import jakarta.resource.spi.ResourceAdapterAssociation; /** * AnnoAdminObjectImpl * * @version $Revision: $ */ @AdministeredObject(adminObjectInterfaces = {AnnoAdminObject.class}) public class AnnoAdminObjectImpl implements AnnoAdminObject, ResourceAdapterAssociation { /** * Serial version uid */ private static final long serialVersionUID = 1L; /** * The resource adapter */ private ResourceAdapter ra; /** * Reference */ private Reference reference; /** * first */ @ConfigProperty(defaultValue = "12345", description = {"1st", "first"}, ignore = true, supportsDynamicUpdates = false, confidential = true) private Long first; /** * second */ private Boolean second; /** * Default constructor */ public AnnoAdminObjectImpl() { } /** * Set first * * @param first The value */ public void setFirst(Long first) { this.first = first; } /** * Get first * * @return The value */ public Long getFirst() { return first; } /** * Set second * * @param second The value */ @ConfigProperty(defaultValue = "false", description = {"2nd", "second"}, ignore = false, supportsDynamicUpdates = true, confidential = false) public void setSecond(Boolean second) { this.second = second; } /** * Get second * * @return The value */ public Boolean getSecond() { return second; } /** * Get the resource adapter * * @return The handle */ public ResourceAdapter getResourceAdapter() { return ra; } /** * Set the resource adapter * * @param ra The handle */ public void setResourceAdapter(ResourceAdapter ra) { this.ra = ra; } /** * Get the Reference instance. * * @return Reference instance * @throws NamingException Thrown if a reference can't be obtained */ @Override public Reference getReference() throws NamingException { return reference; } /** * Set the Reference instance. * * @param reference A Reference instance */ @Override public void setReference(Reference reference) { this.reference = reference; } /** * Returns a hash code value for the object. * * @return A hash code value for this object. */ @Override public int hashCode() { int result = 17; if (first != null) { result += 31 * result + 7 * first.hashCode(); } else { result += 31 * result + 7; } if (second != null) { result += 31 * result + 7 * second.hashCode(); } else { result += 31 * result + 7; } return result; } /** * Indicates whether some other object is equal to this one. * * @param other The reference object with which to compare. * @return true if this object is the same as the obj argument, false * otherwise. */ @Override public boolean equals(Object other) { if (other == null) { return false; } if (other == this) { return true; } if (!(other instanceof AnnoAdminObjectImpl)) { return false; } boolean result = true; AnnoAdminObjectImpl obj = (AnnoAdminObjectImpl) other; if (result) { if (first == null) { result = obj.getFirst() == null; } else { result = first.equals(obj.getFirst()); } } if (result) { if (second == null) { result = obj.getSecond() == null; } else { result = second.equals(obj.getSecond()); } } return result; } }
4,992
25.989189
145
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/annorar/AnnoConnection1.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.annorar; /** * AnnoConnection * * @version $Revision: $ */ public interface AnnoConnection1 { /** * Call me */ void callMe(); /** * Close */ void close(); }
1,273
30.85
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/annorar/AnnoConnectionFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.annorar; import java.io.Serializable; import jakarta.resource.Referenceable; import jakarta.resource.ResourceException; /** * AnnoConnectionFactory * * @version $Revision: $ */ public interface AnnoConnectionFactory extends Serializable, Referenceable { /** * Get connection from factory * * @return AnnoConnection instance * @throws ResourceException Thrown if a connection can't be obtained */ AnnoConnection getConnection() throws ResourceException; }
1,569
35.511628
76
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/annorar/AnnoConnectionFactoryImpl.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.annorar; import org.jboss.logging.Logger; import javax.naming.NamingException; import javax.naming.Reference; import jakarta.resource.ResourceException; import jakarta.resource.spi.ConnectionManager; /** * AnnoConnectionFactoryImpl * * @version $Revision: $ */ public class AnnoConnectionFactoryImpl implements AnnoConnectionFactory { /** * The serial version UID */ private static final long serialVersionUID = 1L; /** * The logger */ private static Logger log = Logger.getLogger("AnnoConnectionFactoryImpl"); /** * Reference */ private Reference reference; /** * ManagedConnectionFactory */ private AnnoManagedConnectionFactory mcf; /** * ConnectionManager */ private ConnectionManager connectionManager; /** * Default constructor */ public AnnoConnectionFactoryImpl() { } /** * Default constructor * * @param mcf ManagedConnectionFactory * @param cxManager ConnectionManager */ public AnnoConnectionFactoryImpl(AnnoManagedConnectionFactory mcf, ConnectionManager cxManager) { this.mcf = mcf; this.connectionManager = cxManager; } /** * Get connection from factory * * @return AnnoConnection instance * @throws ResourceException Thrown if a connection can't be obtained */ @Override public AnnoConnection getConnection() throws ResourceException { log.trace("getConnection()"); return (AnnoConnection) connectionManager.allocateConnection(mcf, null); } /** * Get the Reference instance. * * @return Reference instance * @throws NamingException Thrown if a reference can't be obtained */ @Override public Reference getReference() throws NamingException { log.trace("getReference()"); return reference; } /** * Set the Reference instance. * * @param reference A Reference instance */ @Override public void setReference(Reference reference) { log.trace("setReference()"); this.reference = reference; } }
3,268
27.181034
80
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/archive/ArchiveValidationDeploymentTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.archive; import static org.junit.Assert.fail; import org.jboss.arquillian.container.test.api.Deployer; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.integration.jca.JcaMgmtBase; import org.jboss.as.test.integration.jca.JcaMgmtServerSetupTask; import org.jboss.as.test.integration.jca.rar.MultipleConnectionFactory1; import org.jboss.logging.Logger; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * @author <a href="[email protected]">Vladimir Rastseluev</a> JBQA-6006 archive validation checking */ @RunWith(Arquillian.class) @RunAsClient @ServerSetup(ArchiveValidationDeploymentTestCase.ArchiveValidationDeploymentTestCaseSetup.class) public class ArchiveValidationDeploymentTestCase extends JcaMgmtBase { private static Logger log = Logger.getLogger("ArchiveValidationDeploymentTestCase"); static class ArchiveValidationDeploymentTestCaseSetup extends JcaMgmtServerSetupTask { boolean enabled; boolean failingOnError; boolean failingOnWarning; @Override public void doSetup(ManagementClient managementClient) throws Exception { enabled = getArchiveValidationAttribute("enabled"); failingOnError = getArchiveValidationAttribute("fail-on-error"); failingOnWarning = getArchiveValidationAttribute("fail-on-warn"); log.trace("//save//" + enabled + "//" + failingOnError + "//" + failingOnWarning); } } @ArquillianResource Deployer deployer; /** * Define the deployment * * create rar archive either valid or invalid where archive validation reports warning or error * WARNING: triggered by wrong config property type in MultipleWarningResourceAdapter, int instead of Integer (name property) * ERROR: triggered by missing equals and hashCode in MultipleErrorResourceAdapter * * @return The deployment archive */ public static ResourceAdapterArchive createDeployment(String name) throws Exception { ResourceAdapterArchive raa = ShrinkWrap.create(ResourceAdapterArchive.class, name + ".rar"); JavaArchive ja = ShrinkWrap.create(JavaArchive.class, name + ".jar"); ja.addPackage(MultipleConnectionFactory1.class.getPackage()); raa.addAsLibrary(ja); raa.addAsManifestResource(ArchiveValidationDeploymentTestCase.class.getPackage(), name + "ra.xml", "ra.xml") .addAsManifestResource(ArchiveValidationDeploymentTestCase.class.getPackage(), "ironjacamar.xml", "ironjacamar.xml"); return raa; } /* * this deployment is important to trigger ArchiveValidationDeploymentTestCaseSetup.doSetup() method before first test run */ @Deployment(name = "fake", managed = true) public static Archive<?> deployment() throws Exception { return ShrinkWrap.create(JavaArchive.class, "fake.jar"); } @Deployment(name = "ok", managed = false) public static ResourceAdapterArchive deployment1() throws Exception { return createDeployment("ok_"); } @Deployment(name = "error", managed = false) public static ResourceAdapterArchive deployment2() throws Exception { return createDeployment("error_"); } @Deployment(name = "warning", managed = false) public static ResourceAdapterArchive deployment3() throws Exception { return createDeployment("warning_"); } public void goodTest(String dName) throws Exception { deployer.deploy(dName); deployer.undeploy(dName); } public void badTest(String dName, String description) throws Exception { try { deployer.deploy(dName); fail("'" + dName + "' deployment shouldn't be deployed if " + description); } catch (Exception e) { // nothing } finally { deployer.undeploy(dName); } } @Test public void testValidationDisabled() throws Throwable { setArchiveValidation(false, false, false); goodTest("ok"); goodTest("error"); goodTest("warning"); } @Test public void testValidationDisabled1() throws Throwable { setArchiveValidation(false, true, false); goodTest("ok"); goodTest("error"); goodTest("warning"); } @Test public void testValidationDisabled2() throws Throwable { setArchiveValidation(false, false, true); goodTest("ok"); goodTest("error"); goodTest("warning"); } @Test public void testValidationDisabled3() throws Throwable { setArchiveValidation(false, true, true); goodTest("ok"); goodTest("error"); goodTest("warning"); } @Test public void testValidationEnabled() throws Throwable { setArchiveValidation(true, false, false); goodTest("ok"); goodTest("error"); goodTest("warning"); } @Test public void testValidationOfErrorsEnabled() throws Throwable { setArchiveValidation(true, true, false); goodTest("ok"); badTest("error", "fail on errors is enabled"); goodTest("warning"); } @Test public void testValidationOfErrorsAndWarningsEnabled() throws Throwable { setArchiveValidation(true, true, true); goodTest("ok"); badTest("error", "fail on errors and warnings is enabled"); badTest("warning", "fail on errors and warnings is enabled"); } @Test public void testValidationOfWarningsEnabled() throws Throwable { setArchiveValidation(true, false, true); goodTest("ok"); badTest("error", "fail on warnings is enabled"); badTest("warning", "fail on warnings is enabled"); } }
7,296
34.595122
133
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/capacitypolicies/DatasourceCapacityPoliciesTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.capacitypolicies; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ServerSetup; import org.junit.runner.RunWith; /** * Integration test for Jakarta Connectors capacity policies JBJCA-986 using datasource * * @author <a href="mailto:[email protected]">Martin Simka</a> */ @RunWith(Arquillian.class) @ServerSetup(DatasourceCapacityPoliciesTestCase.DatasourceServerSetupTask.class) public class DatasourceCapacityPoliciesTestCase extends AbstractDatasourceCapacityPoliciesTestCase { public DatasourceCapacityPoliciesTestCase() { // test non-xa datasource super(false); } static class DatasourceServerSetupTask extends AbstractDatasourceCapacityPoliciesTestCase.AbstractDatasourceCapacityPoliciesServerSetup { DatasourceServerSetupTask() { // add non-xa datasource super(false); } } }
1,960
37.45098
141
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/capacitypolicies/XADatasourceCapacityPoliciesTestCase.java
/* * * * JBoss, Home of Professional Open Source. * * Copyright 2015, Red Hat, Inc., and individual contributors * * as indicated by the @author tags. See the copyright.txt file in the * * distribution for a full listing of individual contributors. * * * * This is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as * * published by the Free Software Foundation; either version 2.1 of * * the License, or (at your option) any later version. * * * * This software is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this software; if not, write to the Free * * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * * 02110-1301 USA, or see the FSF site: http://www.fsf.org. * */ package org.jboss.as.test.integration.jca.capacitypolicies; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ServerSetup; import org.junit.runner.RunWith; /** * Integration test for Jakarta Connectors capacity policies JBJCA-986 using xa-datasource * * @author <a href="mailto:[email protected]">Martin Simka</a> */ @RunWith(Arquillian.class) @ServerSetup(XADatasourceCapacityPoliciesTestCase.DatasourceServerSetupTask.class) public class XADatasourceCapacityPoliciesTestCase extends AbstractDatasourceCapacityPoliciesTestCase { public XADatasourceCapacityPoliciesTestCase() { // test xa datasource super(true); } static class DatasourceServerSetupTask extends AbstractDatasourceCapacityPoliciesServerSetup { DatasourceServerSetupTask() { // add xa datasource super(true); } } }
1,979
36.358491
102
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/capacitypolicies/AbstractDatasourceCapacityPoliciesTestCase.java
/* * * * JBoss, Home of Professional Open Source. * * Copyright 2015, Red Hat, Inc., and individual contributors * * as indicated by the @author tags. See the copyright.txt file in the * * distribution for a full listing of individual contributors. * * * * This is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as * * published by the Free Software Foundation; either version 2.1 of * * the License, or (at your option) any later version. * * * * This software is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this software; if not, write to the Free * * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * * 02110-1301 USA, or see the FSF site: http://www.fsf.org. * */ package org.jboss.as.test.integration.jca.capacitypolicies; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ENABLED; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import static org.junit.Assert.fail; import static org.wildfly.common.Assert.checkNotNullParamWithNullPointerException; import java.lang.reflect.ReflectPermission; import java.sql.Connection; import java.util.HashMap; import java.util.Map; import java.io.FilePermission; import java.util.PropertyPermission; import java.util.concurrent.TimeUnit; import jakarta.annotation.Resource; import javax.sql.DataSource; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.connector.subsystems.datasources.WildFlyDataSource; import org.jboss.as.controller.client.ModelControllerClient; import org.jboss.as.test.integration.jca.JcaMgmtBase; import org.jboss.as.test.integration.jca.JcaMgmtServerSetupTask; import org.jboss.as.test.integration.jca.JcaTestsUtil; import org.jboss.as.test.integration.management.ManagementOperations; import org.jboss.as.test.integration.management.base.AbstractMgmtTestBase; import org.jboss.as.test.integration.management.base.ContainerResourceMgmtTestBase; import org.jboss.as.test.integration.management.util.MgmtOperationException; import org.jboss.as.test.shared.TimeoutUtil; import org.jboss.dmr.ModelNode; import org.jboss.jca.adapters.jdbc.WrapperDataSource; import org.jboss.jca.core.connectionmanager.pool.mcp.ManagedConnectionPool; import org.jboss.remoting3.security.RemotingPermission; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; /** * Integration test for Jakarta Connectors capacity policies JBJCA-986 using datasource/xa-datasource * * @author <a href="mailto:[email protected]">Martin Simka</a> */ public abstract class AbstractDatasourceCapacityPoliciesTestCase extends JcaMgmtBase { protected static final String DS_JNDI_NAME = "java:jboss/datasources/TestDatasource"; protected static final String DS_NAME = "TestDatasource"; protected static final ModelNode DS_ADDRESS = new ModelNode().add(SUBSYSTEM, "datasources") .add("data-source", DS_NAME); protected static final ModelNode XA_DS_ADDRESS = new ModelNode().add(SUBSYSTEM, "datasources") .add("xa-data-source", DS_NAME); private final ModelNode statisticsAddress; private final boolean xaDatasource; static { DS_ADDRESS.protect(); XA_DS_ADDRESS.protect(); } public AbstractDatasourceCapacityPoliciesTestCase(boolean xaDatasource) { this.xaDatasource = xaDatasource; statisticsAddress = xaDatasource ? XA_DS_ADDRESS.clone() : DS_ADDRESS.clone(); statisticsAddress.add("statistics", "pool"); statisticsAddress.protect(); } @Resource(mappedName = "java:jboss/datasources/TestDatasource") private DataSource ds; @ArquillianResource private ManagementClient managementClient; @Override protected ModelControllerClient getModelControllerClient() { return managementClient.getControllerClient(); } @Deployment public static Archive<?> createDeployment() { JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "jca-capacity-test.jar"); jar.addClasses(JcaMgmtBase.class, ManagementOperations.class, ContainerResourceMgmtTestBase.class, AbstractMgmtTestBase.class, JcaMgmtServerSetupTask.class, MgmtOperationException.class, AbstractDatasourceCapacityPoliciesTestCase.class, DatasourceCapacityPoliciesTestCase.class, JcaTestsUtil.class, TimeoutUtil.class); jar.addAsManifestResource(new StringAsset("Dependencies: javax.inject.api,org.jboss.as.connector," + "org.jboss.as.controller,org.jboss.dmr,org.jboss.staxmapper," + "org.jboss.ironjacamar.impl, org.jboss.ironjacamar.jdbcadapters,org.jboss.remoting\n"), "MANIFEST.MF"); jar.addAsManifestResource(createPermissionsXmlAsset( new RemotingPermission("createEndpoint"), new RemotingPermission("connect"), new FilePermission(System.getProperty("jboss.inst") + "/standalone/tmp/auth/*", "read"), new PropertyPermission("ts.timeout.factor", "read"), new RuntimePermission("accessDeclaredMembers"), new ReflectPermission("suppressAccessChecks") ), "permissions.xml"); return jar; } /** * Test pool with * org.jboss.jca.core.connectionmanager.pool.capacity.MinPoolSizeDecrementer * org.jboss.jca.core.connectionmanager.pool.capacity.MaxPoolSizeIncrementer" * * @throws Exception */ @Test public void testNonDefaultDecrementerAndIncrementer() throws Exception { checkStatistics(5, 0, 0, 0); Connection[] connections = new Connection[4]; connections[0] = ds.getConnection(); // wait until IJ PoolFiller and CapacityFiller fill pool with expected number of connections, // also remember initial destroyedCount, IJ fills pool with two threads (CapacityFiller and PoolFiller) // and it can result in one connection created and immediately destroyed because pool has been already filled // by other thread, for details see https://issues.jboss.org/browse/JBJCA-1344 int initialDestroyedCount = waitForPool(2000); checkStatistics(4, 1, 5, initialDestroyedCount); connections[1] = ds.getConnection(); checkStatistics(3, 2, 5, initialDestroyedCount); connections[2] = ds.getConnection(); checkStatistics(2, 3, 5, initialDestroyedCount); connections[3] = ds.getConnection(); checkStatistics(1, 4, 5, initialDestroyedCount); for (int i = 0; i < 4; i++) { Connection c = connections[i]; c.close(); } WrapperDataSource wsds = JcaTestsUtil.extractWrapperDatasource((WildFlyDataSource) ds); ManagedConnectionPool mcp = JcaTestsUtil.extractManagedConnectionPool(wsds); JcaTestsUtil.callRemoveIdleConnections(mcp); checkStatistics(5, 0, 2, initialDestroyedCount + 3); } private void checkStatistics(int expectedAvailableCount, int expectedInUseCount, int expectedActiveCount, int expectedDestroyedCount) throws Exception { int availableCount = readStatisticsAttribute("AvailableCount"); int inUseCount = readStatisticsAttribute("InUseCount"); int activeCount = readStatisticsAttribute("ActiveCount"); int destroyedCount = readStatisticsAttribute("DestroyedCount"); Assert.assertEquals("Unexpected AvailableCount", expectedAvailableCount, availableCount); Assert.assertEquals("Unexpected InUseCount", expectedInUseCount, inUseCount); Assert.assertEquals("Unexpected ActiveCount", expectedActiveCount, activeCount); Assert.assertEquals("Unexpected DestroyedCount", expectedDestroyedCount, destroyedCount); } private int readStatisticsAttribute(final String attributeName) throws Exception { return readAttribute(statisticsAddress, attributeName).asInt(); } private int waitForPool(final int timeout) throws Exception { long waitTimeout = TimeoutUtil.adjust(timeout); long sleep = 50L; while (true) { int availableCount = readStatisticsAttribute("AvailableCount"); int inUseCount = readStatisticsAttribute("InUseCount"); int activeCount = readStatisticsAttribute("ActiveCount"); if (availableCount == 4 && inUseCount == 1 && activeCount == 5) return readStatisticsAttribute("DestroyedCount"); TimeUnit.MILLISECONDS.sleep(sleep); waitTimeout -= sleep; if (waitTimeout <= 0) { fail("Pool hasn't been filled with expected connections within specified timeout"); } } } abstract static class AbstractDatasourceCapacityPoliciesServerSetup extends JcaMgmtServerSetupTask { private boolean xa; AbstractDatasourceCapacityPoliciesServerSetup(boolean xa) { this.xa = xa; } @Override public void doSetup(final ManagementClient managementClient) throws Exception { CapacityConfiguration configuration = new CapacityConfiguration( "org.jboss.jca.core.connectionmanager.pool.capacity.MinPoolSizeDecrementer", "org.jboss.jca.core.connectionmanager.pool.capacity.MaxPoolSizeIncrementer"); createDatasource(configuration); } private void createDatasource(CapacityConfiguration capacityConfiguration) throws Exception { ModelNode addOperation = new ModelNode(); addOperation.get(OP).set(ADD); addOperation.get(OP_ADDR).set(xa ? XA_DS_ADDRESS : DS_ADDRESS); addOperation.get("jndi-name").set(DS_JNDI_NAME); addOperation.get("driver-name").set("h2"); addOperation.get("statistics-enabled").set("true"); addOperation.get("enabled").set("false"); addOperation.get("min-pool-size").set(2); addOperation.get("max-pool-size").set(5); addOperation.get("user-name").set("sa"); addOperation.get("password").set("sa"); if (!xa) { addOperation.get("connection-url").set("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"); } if (capacityConfiguration != null) { // add capacity-decrementer-class if (capacityConfiguration.getCapacityDecrementerClass() != null) { addOperation.get("capacity-decrementer-class").set(capacityConfiguration.getCapacityDecrementerClass()); if (!capacityConfiguration.getCapacityDecrementerProperties().isEmpty()) { Map<String, String> properties = capacityConfiguration.getCapacityDecrementerProperties(); addProperties(addOperation, properties); } } // add capacity-incrementer-class if (capacityConfiguration.getCapacityIncrementerClass() != null) { addOperation.get("capacity-incrementer-class").set(capacityConfiguration.getCapacityIncrementerClass()); if (!capacityConfiguration.getCapacityIncrementerProperties().isEmpty()) { Map<String, String> properties = capacityConfiguration.getCapacityIncrementerProperties(); addProperties(addOperation, properties); } } } executeOperation(addOperation); if (xa) { ModelNode xaDatasourcePropertiesAddress = XA_DS_ADDRESS.clone(); xaDatasourcePropertiesAddress.add("xa-datasource-properties", "URL"); xaDatasourcePropertiesAddress.protect(); ModelNode xaDatasourcePropertyOperation = new ModelNode(); xaDatasourcePropertyOperation.get(OP).set("add"); xaDatasourcePropertyOperation.get(OP_ADDR).set(xaDatasourcePropertiesAddress); xaDatasourcePropertyOperation.get("value").set("jdbc:h2:mem:test"); executeOperation(xaDatasourcePropertyOperation); } writeAttribute(xa ? XA_DS_ADDRESS : DS_ADDRESS, ENABLED, "true"); reload(); } private static void addProperties(ModelNode addOperation, Map<String, String> properties) { for (Map.Entry<String, String> entry : properties.entrySet()) { ModelNode props = new ModelNode(); props.add(entry.getKey(), entry.getValue()); addOperation.get("capacity-incrementer-properties").set(props); } } } static class CapacityConfiguration { private String capacityDecrementerClass; private Map<String, String> capacityDecrementerProperties; private String capacityIncrementerClass; private Map<String, String> capacityIncrementerProperties; CapacityConfiguration(String capacityDecrementerClass, String capacityIncrementerClass) { this.capacityDecrementerProperties = new HashMap<>(); this.capacityIncrementerProperties = new HashMap<>(); this.capacityDecrementerClass = capacityDecrementerClass; this.capacityIncrementerClass = capacityIncrementerClass; } void addCapacityDecrementerProperty(String name, String value) { if (capacityDecrementerClass == null) { throw new IllegalStateException("capacityDecrementerClass isn't set"); } checkNotNullParamWithNullPointerException("name", name); checkNotNullParamWithNullPointerException("value", value); capacityDecrementerProperties.put(name, value); } void addCapacityIncrementerProperty(String name, String value) { if (capacityIncrementerClass == null) { throw new IllegalStateException("capacityIncrementerClass isn't set"); } checkNotNullParamWithNullPointerException("name", name); checkNotNullParamWithNullPointerException("value", value); capacityIncrementerProperties.put(name, value); } String getCapacityDecrementerClass() { return capacityDecrementerClass; } Map<String, String> getCapacityDecrementerProperties() { return capacityDecrementerProperties; } String getCapacityIncrementerClass() { return capacityIncrementerClass; } Map<String, String> getCapacityIncrementerProperties() { return capacityIncrementerProperties; } } }
15,705
45.194118
125
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/capacitypolicies/ResourceAdapterCapacityPoliciesTestCase.java
/* * * * JBoss, Home of Professional Open Source. * * Copyright 2015, Red Hat, Inc., and individual contributors * * as indicated by the @author tags. See the copyright.txt file in the * * distribution for a full listing of individual contributors. * * * * This is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as * * published by the Free Software Foundation; either version 2.1 of * * the License, or (at your option) any later version. * * * * This software is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this software; if not, write to the Free * * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * * 02110-1301 USA, or see the FSF site: http://www.fsf.org. * */ package org.jboss.as.test.integration.jca.capacitypolicies; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import static org.junit.Assert.fail; import java.lang.reflect.ReflectPermission; import java.util.List; import java.io.FilePermission; import java.util.PropertyPermission; import java.util.concurrent.TimeUnit; import jakarta.annotation.Resource; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.connector.subsystems.resourceadapters.Namespace; import org.jboss.as.connector.subsystems.resourceadapters.ResourceAdapterSubsystemParser; import org.jboss.as.controller.client.ModelControllerClient; import org.jboss.as.test.integration.jca.JcaMgmtBase; import org.jboss.as.test.integration.jca.JcaTestsUtil; import org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyConnection; import org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyConnectionFactory; import org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyConnectionFactoryImpl; import org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyConnectionImpl; import org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyLocalTransaction; import org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyManagedConnection; import org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyManagedConnectionFactory; import org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyManagedConnectionMetaData; import org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyResourceAdapter; import org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyXAResource; import org.jboss.as.test.integration.management.ManagementOperations; import org.jboss.as.test.integration.management.base.AbstractMgmtServerSetupTask; import org.jboss.as.test.integration.management.base.AbstractMgmtTestBase; import org.jboss.as.test.integration.management.base.ContainerResourceMgmtTestBase; import org.jboss.as.test.integration.management.util.MgmtOperationException; import org.jboss.as.test.shared.FileUtils; import org.jboss.as.test.shared.TimeoutUtil; import org.jboss.dmr.ModelNode; import org.jboss.jca.core.connectionmanager.pool.mcp.ManagedConnectionPool; import org.jboss.remoting3.security.RemotingPermission; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Integration test for Jakarta Connectors capacity policies JBJCA-986 using resource adapter * * * * @author <a href="mailto:[email protected]">Martin Simka</a> */ @RunWith(Arquillian.class) @ServerSetup(ResourceAdapterCapacityPoliciesTestCase.ResourceAdapterCapacityPoliciesServerSetupTask.class) public class ResourceAdapterCapacityPoliciesTestCase extends JcaMgmtBase { private static final String RA_NAME = "capacity-policies-test.rar"; private static final ModelNode RA_ADDRESS = new ModelNode().add(SUBSYSTEM, "resource-adapters") .add("resource-adapter", RA_NAME); // /subsystem=resource-adapters/resource-adapter=capacity-policies-test.rar ... // .../connection-definitions=Lazy/statistics=pool:read-resource(include-runtime=true private static final ModelNode STATISTICS_ADDRESS = RA_ADDRESS.clone().add("connection-definitions", "Lazy") .add("statistics", "pool"); static { RA_ADDRESS.protect(); STATISTICS_ADDRESS.protect(); } @Deployment public static Archive<?> createResourceAdapter() { ResourceAdapterArchive rar = ShrinkWrap.create(ResourceAdapterArchive.class, "capacity-policies-test.rar"); rar.addAsManifestResource(LazyResourceAdapter.class.getPackage(), "ra-notx.xml", "ra.xml"); JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "capacity-policies-test.jar"); jar.addClass(LazyResourceAdapter.class) .addClass(LazyManagedConnectionFactory.class) .addClass(LazyManagedConnection.class) .addClass(LazyConnection.class) .addClass(LazyConnectionImpl.class) .addClass(LazyXAResource.class) .addClass(LazyLocalTransaction.class) .addClass(LazyManagedConnectionMetaData.class) .addClass(LazyConnectionFactory.class) .addClass(LazyConnectionFactoryImpl.class); jar.addClasses( ResourceAdapterCapacityPoliciesTestCase.class, AbstractMgmtServerSetupTask.class, AbstractMgmtTestBase.class, JcaMgmtBase.class, ContainerResourceMgmtTestBase.class, MgmtOperationException.class, ManagementOperations.class, JcaTestsUtil.class, TimeoutUtil.class); rar.addAsManifestResource(new StringAsset("Dependencies: javax.inject.api,org.jboss.as.connector," + "org.jboss.as.controller,org.jboss.dmr,org.jboss.staxmapper," + "org.jboss.ironjacamar.impl, org.jboss.ironjacamar.jdbcadapters,org.jboss.remoting\n"), "MANIFEST.MF"); rar.addAsManifestResource(createPermissionsXmlAsset( new RemotingPermission("createEndpoint"), new RemotingPermission("connect"), new FilePermission(System.getProperty("jboss.inst") + "/standalone/tmp/auth/*", "read"), new PropertyPermission("ts.timeout.factor", "read"), new RuntimePermission("accessDeclaredMembers"), new ReflectPermission("suppressAccessChecks") ), "permissions.xml"); rar.addAsLibrary(jar); return rar; } @Resource(mappedName = "java:/eis/Lazy") private LazyConnectionFactory lcf; @ArquillianResource private ManagementClient managementClient; @Override protected ModelControllerClient getModelControllerClient() { return managementClient.getControllerClient(); } /** * Test pool with * org.jboss.jca.core.connectionmanager.pool.capacity.MinPoolSizeDecrementer * org.jboss.jca.core.connectionmanager.pool.capacity.MaxPoolSizeIncrementer" * * @throws Exception */ @Test public void testNonDefaultDecrementerAndIncrementer() throws Exception { checkStatistics(5, 0, 0, 0); LazyConnection[] connections = new LazyConnection[4]; connections[0] = lcf.getConnection(); // wait until IJ PoolFiller and CapacityFiller fill pool with expected number of connections, // also remember initial destroyedCount, IJ fills pool with two threads (CapacityFiller and PoolFiller) // and it can result in one connection created and immediately destroyed because pool has been already filled // by other thread, for details see https://issues.jboss.org/browse/JBJCA-1344 int initialDestroyedCount = waitForPool(2000); checkStatistics(4, 1, 5, initialDestroyedCount); connections[1] = lcf.getConnection(); checkStatistics(3, 2, 5, initialDestroyedCount); connections[2] = lcf.getConnection(); checkStatistics(2, 3, 5, initialDestroyedCount); connections[3] = lcf.getConnection(); checkStatistics(1, 4, 5, initialDestroyedCount); for (int i = 0; i < 4; i++) { LazyConnection c = connections[i]; c.close(); } ManagedConnectionPool mcp = JcaTestsUtil.extractManagedConnectionPool(lcf); JcaTestsUtil.callRemoveIdleConnections(mcp); checkStatistics(5, 0, 2, initialDestroyedCount + 3); } private void checkStatistics(int expectedAvailableCount, int expectedInUseCount, int expectedActiveCount, int expectedDestroyedCount) throws Exception { int availableCount = readStatisticsAttribute("AvailableCount"); int inUseCount = readStatisticsAttribute("InUseCount"); int activeCount = readStatisticsAttribute("ActiveCount"); int destroyedCount = readStatisticsAttribute("DestroyedCount"); Assert.assertEquals("Unexpected AvailableCount", expectedAvailableCount, availableCount); Assert.assertEquals("Unexpected InUseCount", expectedInUseCount, inUseCount); Assert.assertEquals("Unexpected ActiveCount", expectedActiveCount, activeCount); Assert.assertEquals("Unexpected DestroyedCount", expectedDestroyedCount, destroyedCount); } private int readStatisticsAttribute(final String attributeName) throws Exception { return readAttribute(STATISTICS_ADDRESS, attributeName).asInt(); } private int waitForPool(final int timeout) throws Exception { long waitTimeout = TimeoutUtil.adjust(timeout); long sleep = 50L; while (true) { int availableCount = readStatisticsAttribute("AvailableCount"); int inUseCount = readStatisticsAttribute("InUseCount"); int activeCount = readStatisticsAttribute("ActiveCount"); if (availableCount == 4 && inUseCount == 1 && activeCount == 5) return readStatisticsAttribute("DestroyedCount"); TimeUnit.MILLISECONDS.sleep(sleep); waitTimeout -= sleep; if (waitTimeout <= 0) { fail("Pool hasn't been filled with expected connections within specified timeout"); } } } static class ResourceAdapterCapacityPoliciesServerSetupTask extends AbstractMgmtServerSetupTask { @Override public void doSetup(final ManagementClient managementClient) throws Exception { String xml = FileUtils.readFile(ResourceAdapterCapacityPoliciesTestCase.class, "ra-def.xml"); List<ModelNode> operations = xmlToModelOperations(xml, Namespace.RESOURCEADAPTERS_1_1.getUriString(), new ResourceAdapterSubsystemParser()); executeOperation(operationListToCompositeOperation(operations)); } @Override public void tearDown(final ManagementClient managementClient, final String containerId) throws Exception { remove(RA_ADDRESS); } } }
11,768
46.26506
152
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/deployment/ITestStatelessEjbAO.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.deployment; import jakarta.ejb.Local; /** * This is interface for the stateless ejb. */ @Local public interface ITestStatelessEjbAO { boolean validateConnectorResource(String jndiName); }
1,262
36.147059
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/deployment/JndiViewOperationJMSTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2020, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.deployment; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.integration.jca.JcaMgmtBase; import org.jboss.as.test.integration.jca.rar.MultipleAdminObject1; import org.jboss.dmr.ModelNode; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.*; /** * Test the situation when connection factory or Jakarta Messaging destination is configured for resource adapter * * @author <a href="[email protected]">Parul Sharma</a> */ @RunWith(Arquillian.class) @RunAsClient public class JndiViewOperationJMSTestCase extends JcaMgmtBase { static final String rarDeploymentName = "eis.rar"; @Deployment(name = "rar", order = 1) public static Archive<?> deploytRar() { ResourceAdapterArchive raa = ShrinkWrap.create(ResourceAdapterArchive.class, rarDeploymentName); JavaArchive ja = ShrinkWrap.create(JavaArchive.class, "lib.jar"); ja.addPackage(MultipleAdminObject1.class.getPackage()); raa.addAsLibrary(ja); raa.addAsManifestResource(JndiViewOperationJMSTestCase.class.getPackage(), "ra.xml", "ra.xml"); return raa; } @Test public void testValueOfJms() throws Exception { ModelNode address = null; try { address = setup(); ModelNode addr = getAddress(); ModelNode operation = getOperation(addr); ModelNode result = executeOperation(operation); ModelNode value = result.get("java: contexts", "java:jboss", "Name3", "class-name"); Assert.assertEquals("org.jboss.as.test.integration.jca.rar.MultipleAdminObject1Impl", value.asString()); } finally { if (address != null) { remove(address); } } } private ModelNode getAddress() { return new ModelNode().add(SUBSYSTEM, "naming"); } private ModelNode getOperation(ModelNode address) { ModelNode operation = new ModelNode(); operation.get(OP).set("jndi-view"); operation.get(OP_ADDR).set(address); return operation; } private ModelNode setup() throws Exception { ModelNode address = new ModelNode(); address.add(SUBSYSTEM, "resource-adapters"); address.add("resource-adapter", rarDeploymentName); address.protect(); ModelNode operation = new ModelNode(); operation.get(OP).set("add"); operation.get(OP_ADDR).set(address); operation.get("archive").set(rarDeploymentName); executeOperation(operation); ModelNode addr = address.clone(); addr.add("admin-objects", "ij_Pool3"); operation = new ModelNode(); operation.get(OP).set("add"); operation.get(OP_ADDR).set(addr); operation.get("jndi-name").set("java:jboss/Name3"); operation .get("class-name") .set("org.jboss.as.test.integration.jca.rar.MultipleAdminObject1Impl"); executeOperation(operation); operation = new ModelNode(); operation.get(OP).set("activate"); operation.get(OP_ADDR).set(address); executeOperation(operation); return address; } }
4,651
36.216
116
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/deployment/EjbTestServlet.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.deployment; import java.io.IOException; import java.io.PrintWriter; import jakarta.ejb.EJB; import javax.naming.InitialContext; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.jboss.logging.Logger; /* * In order for these tests to pass, we must have whitebox-tx.rar configured & deployed. * This is a connection resource which is typically done as part of config.vi, but since * it is a new anno, we want to do it here. But like the connection resources, this also * will not work unless the corresponding RA for this resource is first deployed. * (note: whitebox-tx.rar should be deployed as part of initial config) * */ public class EjbTestServlet extends HttpServlet { @EJB private ITestStatelessEjb testStatelessEjb; @EJB private ITestStatelessEjbAO testStatelessEjbAO; private String servletAppContext = null; private String testMethod = null; private String RARJndiScope = null; private static final long serialVersionUID = 1L; private static final Logger log = Logger.getLogger(EjbTestServlet.class); protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //SecurityClient client = null; try { InitialContext ctx = new InitialContext(); boolean testPassed; testPassed = testStatelessEjbAO.validateConnectorResource("java:app/rardeployment/AppAdmin"); if (!testPassed) { throw new ServletException("Failed to access AppAdmin"); } testPassed = testStatelessEjbAO.validateConnectorResource("java:comp/rardeployment/CompAdmin"); if (!testPassed) { throw new ServletException("Failed to access CompAdmin"); } testPassed = testStatelessEjbAO.validateConnectorResource("java:module/rardeployment/ModuleAdmin"); if (!testPassed) { throw new ServletException("Failed to access ModuleAdmin"); } testPassed = testStatelessEjbAO.validateConnectorResource("java:global/rardeployment/GlobalAdmin"); if (!testPassed) { throw new ServletException("Failed to access GlobalAdmin"); } testPassed = testStatelessEjb.validateConnectorResource("java:app/rardeployment/AppCF"); if (!testPassed) { throw new ServletException("Failed to access AppCF"); } testPassed = testStatelessEjb.validateConnectorResource("java:comp/rardeployment/CompCF"); if (!testPassed) { throw new ServletException("Failed to access CompCF"); } testPassed = testStatelessEjb.validateConnectorResource("java:module/rardeployment/ModuleCF"); if (!testPassed) { throw new ServletException("Failed to access ModuleCF"); } testPassed = testStatelessEjb.validateConnectorResource("java:global/rardeployment/GlobalCF"); if (!testPassed) { throw new ServletException("Failed to access GlobalCF"); } } catch (ServletException se) { log.error(se); throw se; } catch (Exception e) { log.error(e); throw new ServletException("Failed to access resource adapter", e); } finally { //client.logout(); } response.setContentType("text/plain"); PrintWriter out = response.getWriter(); out.print("EjbTestServlet OK"); out.close(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } }
4,929
41.136752
130
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/deployment/ITestStatelessEjb.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.deployment; import jakarta.ejb.Local; /** * This is interface for the stateless ejb. */ @Local public interface ITestStatelessEjb { boolean validateConnectorResource(String jndiName); }
1,260
36.088235
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/deployment/EjbDeploymentTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.deployment; import java.net.URL; import java.util.concurrent.TimeUnit; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.OperateOnDeployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.test.integration.common.HttpRequest; import org.jboss.as.test.integration.jca.rar.MultipleAdminObject1; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Test case for servlet activations * * @author <a href="[email protected]">Jesper Pedersen</a> */ @RunWith(Arquillian.class) @RunAsClient public class EjbDeploymentTestCase { static final String deploymentName = "raractivation.ear"; static final String rarDeploymentName = "eis.rar"; static final String insideRarDeploymentName = "inside-eis.rar"; static final String webDeploymentName = "web.war"; static final String ejbDeploymentName = "ejb.jar"; @Deployment(name = "rar", order = 1) public static Archive<?> deploytRar() { ResourceAdapterArchive raa = ShrinkWrap.create(ResourceAdapterArchive.class, rarDeploymentName); JavaArchive ja = ShrinkWrap.create(JavaArchive.class, "lib.jar"); ja.addPackage(MultipleAdminObject1.class.getPackage()); raa.addAsLibrary(ja); raa.addAsManifestResource(EjbDeploymentTestCase.class.getPackage(), "ra.xml", "ra.xml"); return raa; } public static Archive<?> getRar() { ResourceAdapterArchive raa = ShrinkWrap.create(ResourceAdapterArchive.class, insideRarDeploymentName); JavaArchive ja = ShrinkWrap.create(JavaArchive.class, "lib.jar"); ja.addPackage(MultipleAdminObject1.class.getPackage()); raa.addAsLibrary(ja); raa.addAsManifestResource(EjbDeploymentTestCase.class.getPackage(), "ra.xml", "ra.xml"); return raa; } public static Archive<?> getEjb() { JavaArchive jar = ShrinkWrap.create(JavaArchive.class, ejbDeploymentName); //jar.addClass(ITestStatelessEjb.class); jar.addClass(TestStatelessEjb.class); jar.addClass(TestStatelessEjbAO.class); //jar.addAsManifestResource(new StringAsset("Dependencies: deployment." + rarDeploymentName + "\n"), "MANIFEST.MF"); return jar; } public static Archive<?> getWar() { WebArchive war = ShrinkWrap.create(WebArchive.class, webDeploymentName); war.addClass(EjbTestServlet.class); war.addAsWebInfResource(EjbDeploymentTestCase.class.getPackage(), "ejb-web.xml", "web.xml"); //war.addAsManifestResource(new StringAsset("Dependencies: deployment." + rarDeploymentName + "\n"), "MANIFEST.MF"); return war; } @Deployment(name = "ear", order = 2) public static Archive<?> deployEar() { EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, deploymentName); JavaArchive ja = ShrinkWrap.create(JavaArchive.class, "lib.jar"); ja.addClass(ITestStatelessEjb.class); ja.addClass(ITestStatelessEjbAO.class); ear.addAsLibraries(ja); ear.addAsModule(getRar()); ear.addAsModule(getWar()); ear.addAsModule(getEjb()); //ear.addAsManifestResource(EjbDeploymentTestCase.class.getPackage(), "application.xml", "application.xml"); ear.addAsManifestResource(new StringAsset("Dependencies: deployment." + rarDeploymentName + "\n"), "MANIFEST.MF"); return ear; } @ArquillianResource @OperateOnDeployment("ear") private URL earUrl; /** * Test EAR * * @throws Throwable Thrown if case of an error */ @Test public void testEAR() throws Exception { String res = HttpRequest.get(earUrl.toExternalForm() + "EjbTestServlet", 4, TimeUnit.SECONDS); Assert.assertEquals("EjbTestServlet OK", res); } }
5,382
38.291971
124
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/deployment/RARServlet.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.deployment; import java.io.IOException; import java.io.PrintWriter; import jakarta.annotation.Resource; import javax.naming.InitialContext; import jakarta.resource.AdministeredObjectDefinition; import jakarta.resource.AdministeredObjectDefinitions; import jakarta.resource.ConnectionFactoryDefinition; import jakarta.resource.ConnectionFactoryDefinitions; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.jboss.as.test.integration.jca.rar.MultipleAdminObject1; import org.jboss.as.test.integration.jca.rar.MultipleConnectionFactory1; import org.jboss.logging.Logger; //import org.jboss.security.client.SecurityClient; //import org.jboss.security.client.SecurityClientFactory; @AdministeredObjectDefinition(className = "org.jboss.as.test.integration.jca.rar.MultipleAdminObject1Impl", name = "java:app/rardeployment/AppAdmin", resourceAdapter = "eis.rar") @AdministeredObjectDefinitions({ @AdministeredObjectDefinition( className = "org.jboss.as.test.integration.jca.rar.MultipleAdminObject1Impl", name = "java:comp/rardeployment/CompAdmin", resourceAdapter = "eis"), @AdministeredObjectDefinition( className = "org.jboss.as.test.integration.jca.rar.MultipleAdminObject1Impl", name = "java:module/rardeployment/ModuleAdmin", resourceAdapter = "eis.rar"), @AdministeredObjectDefinition( className = "org.jboss.as.test.integration.jca.rar.MultipleAdminObject1Impl", name = "java:global/rardeployment/GlobalAdmin", resourceAdapter = "eis") }) @ConnectionFactoryDefinition(interfaceName = "org.jboss.as.test.integration.jca.rar.MultipleConnectionFactory1", name = "java:app/rardeployment/AppCF", resourceAdapter = "eis.rar") @ConnectionFactoryDefinitions({ @ConnectionFactoryDefinition( interfaceName = "org.jboss.as.test.integration.jca.rar.MultipleConnectionFactory1", name = "java:comp/rardeployment/CompCF", resourceAdapter = "eis"), @ConnectionFactoryDefinition( interfaceName = "org.jboss.as.test.integration.jca.rar.MultipleConnectionFactory1", name = "java:module/rardeployment/ModuleCF", resourceAdapter = "eis.rar"), @ConnectionFactoryDefinition( interfaceName = "org.jboss.as.test.integration.jca.rar.MultipleConnectionFactory1", name = "java:global/rardeployment/GlobalCF", resourceAdapter = "eis") }) /** * A servlet that accesses a resource adapter deployments. */ public class RARServlet extends HttpServlet { private static final long serialVersionUID = 1L; private static final Logger log = Logger.getLogger(RARServlet.class); @Resource(lookup = "java:app/rardeployment/xml/ao") private MultipleAdminObject1 xmlAO; @Resource(name = "xml/cf") private MultipleConnectionFactory1 xmlCF; protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //SecurityClient client = null; try { InitialContext ctx = new InitialContext(); //client = SecurityClientFactory.getSecurityClient(); //client.setSimple("user1", "password1"); //client.login(); Object appAdmin = ctx.lookup("java:app/rardeployment/AppAdmin"); if (appAdmin == null) { throw new ServletException("Failed to access AppAdmin"); } Object compAdmin = ctx.lookup("java:comp/rardeployment/CompAdmin"); if (compAdmin == null) { throw new ServletException("Failed to access CompAdmin"); } Object moduleAdmin = ctx.lookup("java:module/rardeployment/ModuleAdmin"); if (moduleAdmin == null) { throw new ServletException("Failed to access ModuleAdmin"); } Object globalAdmin = ctx.lookup("java:global/rardeployment/GlobalAdmin"); if (globalAdmin == null) { throw new ServletException("Failed to access GlobalAdmin"); } Object appCF = ctx.lookup("java:app/rardeployment/AppCF"); if (appCF == null) { throw new ServletException("Failed to access AppCF"); } Object compCF = ctx.lookup("java:comp/rardeployment/CompCF"); if (compCF == null) { throw new ServletException("Failed to access CompCF"); } Object moduleCF = ctx.lookup("java:module/rardeployment/ModuleCF"); if (moduleCF == null) { throw new ServletException("Failed to access ModuleCF"); } Object globalCF = ctx.lookup("java:global/rardeployment/GlobalCF"); if (globalCF == null) { throw new ServletException("Failed to access GlobalCF"); } if (xmlAO == null) { throw new ServletException("Failed to retrieve AO defined in xml descriptor"); } if (xmlCF == null) { throw new ServletException("Failed to retrieve CF defined in xml descriptor"); } } catch (ServletException se) { log.error(se); throw se; } catch (Exception e) { log.error(e); throw new ServletException("Failed to access resource adapter", e); } finally { //client.logout(); } response.setContentType("text/plain"); PrintWriter out = response.getWriter(); out.print("RARServlet OK"); out.close(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } }
7,025
45.223684
130
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/deployment/WarServletDeploymentTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.deployment; import java.net.URL; import java.util.concurrent.TimeUnit; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.OperateOnDeployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.test.integration.common.HttpRequest; import org.jboss.as.test.integration.jca.rar.MultipleAdminObject1; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Test case for servlet activations * * @author <a href="[email protected]">Jesper Pedersen</a> */ @RunWith(Arquillian.class) @RunAsClient public class WarServletDeploymentTestCase { static final String deploymentName = "raractivation.ear"; static final String rarDeploymentName = "eis.rar"; static final String webDeploymentName = "web.war"; @Deployment(name = "rar", order = 1) public static Archive<?> getRar() { ResourceAdapterArchive raa = ShrinkWrap.create(ResourceAdapterArchive.class, rarDeploymentName); JavaArchive ja = ShrinkWrap.create(JavaArchive.class, "lib.jar"); ja.addPackage(MultipleAdminObject1.class.getPackage()); raa.addAsLibrary(ja); raa.addAsManifestResource(WarServletDeploymentTestCase.class.getPackage(), "ra.xml", "ra.xml"); return raa; } @Deployment(name = "web", order = 2) public static Archive<?> getWar() { WebArchive war = ShrinkWrap.create(WebArchive.class, webDeploymentName); war.addClass(RARServlet.class); war.addAsWebInfResource(WarServletDeploymentTestCase.class.getPackage(), "web.xml", "web.xml"); war.addAsManifestResource(new StringAsset("Dependencies: deployment." + rarDeploymentName + "\n"), "MANIFEST.MF"); return war; } @ArquillianResource @OperateOnDeployment("web") private URL webUrl; /** * Test web * * @throws Throwable Thrown if case of an error */ @Test public void testWeb() throws Exception { String res = HttpRequest.get(webUrl.toExternalForm() + "RARServlet", 4, TimeUnit.SECONDS); Assert.assertEquals("RARServlet OK", res); } }
3,630
36.05102
122
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/deployment/TestStatelessEjb.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.deployment; import jakarta.ejb.Stateless; import javax.naming.InitialContext; import jakarta.resource.ConnectionFactoryDefinition; import jakarta.resource.ConnectionFactoryDefinitions; /** * This is the impl for a stateless ejb. */ @ConnectionFactoryDefinition(interfaceName = "org.jboss.as.test.integration.jca.rar.MultipleConnectionFactory1", name = "java:app/rardeployment/AppCF", resourceAdapter = "eis.rar") @ConnectionFactoryDefinitions({ @ConnectionFactoryDefinition( interfaceName = "org.jboss.as.test.integration.jca.rar.MultipleConnectionFactory1", name = "java:comp/rardeployment/CompCF", resourceAdapter = "eis"), @ConnectionFactoryDefinition( interfaceName = "org.jboss.as.test.integration.jca.rar.MultipleConnectionFactory1", name = "java:module/rardeployment/ModuleCF", resourceAdapter = "eis.rar"), @ConnectionFactoryDefinition( interfaceName = "org.jboss.as.test.integration.jca.rar.MultipleConnectionFactory1", name = "java:global/rardeployment/GlobalCF", resourceAdapter = "eis") }) @Stateless public class TestStatelessEjb implements ITestStatelessEjb { public boolean validateConnectorResource(String jndiName) { boolean rval = false; try { InitialContext ctx = new InitialContext(); Object obj = ctx.lookup(jndiName); rval = obj != null; } catch (Exception e) { debug("Fail to access connector resource: " + jndiName); e.printStackTrace(); } return rval; } private void debug(String str) { //System.out.println(str); } }
2,827
37.216216
112
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/deployment/TestStatelessEjbAO.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.deployment; import jakarta.ejb.Stateless; import javax.naming.InitialContext; import jakarta.resource.AdministeredObjectDefinition; import jakarta.resource.AdministeredObjectDefinitions; /** * This is the impl for a stateless ejb. */ @AdministeredObjectDefinition(className = "org.jboss.as.test.integration.jca.rar.MultipleAdminObject1Impl", name = "java:app/rardeployment/AppAdmin", resourceAdapter = "#inside-eis.rar") @AdministeredObjectDefinitions({ @AdministeredObjectDefinition( className = "org.jboss.as.test.integration.jca.rar.MultipleAdminObject1Impl", name = "java:comp/rardeployment/CompAdmin", resourceAdapter = "#inside-eis"), @AdministeredObjectDefinition( className = "org.jboss.as.test.integration.jca.rar.MultipleAdminObject1Impl", name = "java:module/rardeployment/ModuleAdmin", resourceAdapter = "#inside-eis.rar"), @AdministeredObjectDefinition( className = "org.jboss.as.test.integration.jca.rar.MultipleAdminObject1Impl", name = "java:global/rardeployment/GlobalAdmin", resourceAdapter = "#inside-eis") }) @Stateless public class TestStatelessEjbAO implements ITestStatelessEjbAO { public boolean validateConnectorResource(String jndiName) { boolean rval = false; try { InitialContext ctx = new InitialContext(); Object obj = ctx.lookup(jndiName); rval = obj != null; } catch (Exception e) { debug("Fail to access connector resource: " + jndiName); e.printStackTrace(); } return rval; } private void debug(String str) { //System.out.println(str); } }
2,858
37.635135
107
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/ijdeployment/IronJacamarDeploymentTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.ijdeployment; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.INCLUDE_RUNTIME; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RECURSIVE; import static org.jboss.as.test.integration.management.jca.ComplexPropertiesParseUtils.checkModelParams; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.Properties; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.integration.jca.beanvalidation.ra.ValidResourceAdapter; import org.jboss.as.test.integration.management.base.ContainerResourceMgmtTestBase; import org.jboss.dmr.ModelNode; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive; //import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; /** * JBQA-6277 -IronJacamar deployments subsystem test case * * @author <a href="[email protected]">Vladimir Rastseluev</a> */ @RunWith(Arquillian.class) @RunAsClient public class IronJacamarDeploymentTestCase extends ContainerResourceMgmtTestBase { /** * Define the deployment * * @return The deployment archive */ @Deployment public static ResourceAdapterArchive createDeployment() { String deploymentName = "ij.rar"; ResourceAdapterArchive raa = ShrinkWrap.create(ResourceAdapterArchive.class, deploymentName); JavaArchive ja = ShrinkWrap.create(JavaArchive.class, "ij.jar"); ja.addPackage(ValidResourceAdapter.class.getPackage()); raa.addAsLibrary(ja); raa.addAsManifestResource(IronJacamarDeploymentTestCase.class.getPackage(), "ra.xml", "ra.xml") .addAsManifestResource(IronJacamarDeploymentTestCase.class.getPackage(), "ironjacamar.xml", "ironjacamar.xml") .addAsManifestResource( new StringAsset( "Dependencies: javax.inject.api,org.jboss.as.connector\n"), "MANIFEST.MF"); return raa; } /** * Test configuration - if all properties propagated to the model * * @throws Throwable Thrown if case of an error */ @Test public void testConfiguration() throws Throwable { ModelNode address = new ModelNode(); address.add("deployment", "ij.rar").add("subsystem", "resource-adapters").add("ironjacamar", "ironjacamar") .add("resource-adapter", "ij.rar"); ModelNode operation = new ModelNode(); operation.get(OP).set("read-resource"); operation.get(OP_ADDR).set(address); operation.get(RECURSIVE).set(true); operation.get(INCLUDE_RUNTIME).set(true); ModelNode result = executeOperation(operation); assertEquals("Bootstrap-context value is wrong", result.get("bootstrap-context").asString(), "default"); assertEquals("Transaction-support value is wrong", result.get("transaction-support").asString(), "XATransaction"); assertEquals("RA config property value is wrong", result.get("config-properties", "raProperty", "value").asString(), "4"); assertEquals( "Bean validation groups set wrong", result.get("beanvalidationgroups").asString(), "[\"org.jboss.as.test.integration.jca.beanvalidation.ra.ValidGroup\",\"org.jboss.as.test.integration.jca.beanvalidation.ra.ValidGroup1\"]"); ModelNode node = result.get("admin-objects", "java:jboss/VAO"); Properties params = getAOProperties(true); assertTrue("compare failed, node:" + node.asString() + "\nparams:" + params, checkModelParams(node, params)); assertEquals("AO config property value is wrong", node.get("config-properties", "aoProperty", "value").asString(), "admin"); node = result.get("admin-objects", "java:jboss/VAO1"); params = getAOProperties(false); assertTrue("compare failed, node:" + node.asString() + "\nparams:" + params, checkModelParams(node, params)); assertEquals("AO1 config property value is wrong", node.get("config-properties", "aoProperty", "value").asString(), "admin1"); node = result.get("connection-definitions", "java:jboss/VCF"); params = getCFProperties(true); assertTrue("compare failed, node:" + node.asString() + "\nparams:" + params, checkModelParams(node, params)); assertEquals("CF config property value is wrong", node.get("config-properties", "cfProperty", "value").asString(), "first"); assertEquals("Recovery plugin property value is wrong", "C", node.get("recovery-plugin-properties", "Property") .asString()); node = result.get("connection-definitions", "java:jboss/VCF1"); params = getCFProperties(false); assertTrue("compare failed, node:" + node.asString() + "\nparams:" + params, checkModelParams(node, params)); assertEquals("CF1 config property value is wrong", node.get("config-properties", "cfProperty", "value").asString(), "2nd"); assertEquals("Recovery plugin 1 property value is wrong", "C", node.get("recovery-plugin-properties", "Property") .asString()); } /** * Get Properties for admin object * * @param firstAO - true - for first, false - for second * @return */ public Properties getAOProperties(boolean firstAO) { Properties prop = new Properties(); String add = (firstAO ? "" : "1"); String bool = String.valueOf(firstAO); prop.put("class-name", "org.jboss.as.test.integration.jca.beanvalidation.ra.ValidAdminObjectImpl" + add); prop.put("jndi-name", "java:jboss/VAO" + add); prop.put("enabled", bool); prop.put("use-java-context", bool); return prop; } /** * Get Properties for connection factory * * @param firstCF - true - for first, false - for second * @return */ public Properties getCFProperties(boolean firstCF) { Properties prop = new Properties(); String add = (firstCF ? "" : "1"); String bool = String.valueOf(firstCF); prop.put("class-name", "org.jboss.as.test.integration.jca.beanvalidation.ra.ValidManagedConnectionFactory" + add); prop.put("jndi-name", "java:jboss/VCF" + add); prop.put("enabled", bool); prop.put("use-java-context", bool); prop.put("use-ccm", bool); prop.put("min-pool-size", "1"); prop.put("max-pool-size", "5"); prop.put("pool-prefill", bool); prop.put("pool-use-strict-min", bool); prop.put("same-rm-override", bool); prop.put("interleaving", bool); prop.put("no-tx-separate-pool", bool); prop.put("pad-xid", bool); prop.put("wrap-xa-resource", bool); prop.put("flush-strategy", firstCF ? "IDLE_CONNECTIONS" : "ENTIRE_POOL"); if (true) { prop.put("security-application", bool); prop.put("recovery-username", "sa"); prop.put("recovery-password", "sa-pass"); } else { prop.put("security-domain", "HsqlDbRealm"); prop.put("recovery-security-domain", "HsqlDbRealm"); } prop.put("blocking-timeout-wait-millis", "5000"); prop.put("idle-timeout-minutes", "4"); prop.put("allocation-retry", "2"); prop.put("allocation-retry-wait-millis", "3000"); prop.put("xa-resource-timeout", "300"); prop.put("background-validation", bool); prop.put("background-validation-millis", "5000"); prop.put("use-fast-fail", bool); prop.put("no-recovery", bool); prop.put("recovery-plugin-class-name", "someClass2"); return prop; } }
9,289
44.990099
156
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/ijdeployment/IronJacamarDoubleDeploymentTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.ijdeployment; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DEPLOYMENT; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RECURSIVE; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBDEPLOYMENT; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.integration.jca.beanvalidation.ra.ValidResourceAdapter; import org.jboss.as.test.integration.management.base.ContainerResourceMgmtTestBase; import org.jboss.dmr.ModelNode; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive; //import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; /** * Test of two ear ij deployments conflict. * * @author baranowb */ @RunWith(Arquillian.class) @RunAsClient public class IronJacamarDoubleDeploymentTestCase extends ContainerResourceMgmtTestBase { private static final String deploymentName = "test-ij.ear"; private static final String deployment2Name = "test-ij2.ear"; private static final String deploymentConfigName = "ironjacamar.xml"; private static final String deployment2ConfigName = "ironjacamar-2.xml"; private static final String subDeploymentName = "ij.rar"; private static ResourceAdapterArchive createSubDeployment(final String configName) throws Exception { String deploymentName = subDeploymentName; ResourceAdapterArchive raa = ShrinkWrap.create(ResourceAdapterArchive.class, deploymentName); JavaArchive ja = ShrinkWrap.create(JavaArchive.class, "ij.jar"); ja.addPackage(ValidResourceAdapter.class.getPackage()); raa.addAsLibrary(ja); raa.addAsManifestResource(IronJacamarDoubleDeploymentTestCase.class.getPackage(), "ra.xml", "ra.xml") .addAsManifestResource(IronJacamarDoubleDeploymentTestCase.class.getPackage(), configName, "ironjacamar.xml") .addAsManifestResource( new StringAsset( "Dependencies: javax.inject.api,org.jboss.as.connector\n"), "MANIFEST.MF"); return raa; } @Deployment(name = deploymentName) public static EnterpriseArchive createEARDeployment() throws Exception { ResourceAdapterArchive raa = createSubDeployment(deploymentConfigName); EnterpriseArchive earTest = ShrinkWrap.create(EnterpriseArchive.class, deploymentName); earTest.addAsManifestResource(IronJacamarDoubleDeploymentTestCase.class.getPackage(), "application.xml", "application.xml"); earTest.addAsModule(raa); return earTest; } @Deployment(name = deployment2Name) public static EnterpriseArchive createEAR2Deployment() throws Exception { ResourceAdapterArchive raa = createSubDeployment(deployment2ConfigName); EnterpriseArchive earTest = ShrinkWrap.create(EnterpriseArchive.class, deployment2Name); earTest.addAsManifestResource(IronJacamarDoubleDeploymentTestCase.class.getPackage(), "application.xml", "application.xml"); earTest.addAsModule(raa); return earTest; } /** * */ @Test public void testEarConfiguration() throws Throwable { ModelNode address = getAddress(deploymentName); final ModelNode operation = new ModelNode(); operation.get(OP).set("read-resource"); operation.get(OP_ADDR).set(address); operation.get(RECURSIVE).set(true); executeOperation(operation); address = getAddress(deployment2Name); operation.get(OP_ADDR).set(address); executeOperation(operation); } private ModelNode getAddress(String deploymentName) { final ModelNode address = new ModelNode(); address.add(DEPLOYMENT, deploymentName).add(SUBDEPLOYMENT, subDeploymentName).add(SUBSYSTEM, "resource-adapters") .add("ironjacamar", "ironjacamar").add("resource-adapter", deploymentName + "#ij.rar"); address.protect(); return address; } }
5,693
43.139535
125
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/metrics/DriverCfgMetricUnitTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.metrics; import static org.junit.Assert.assertEquals; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; /** * XA datasource configuration and metrics unit test. * * @author <a href="mailto:[email protected]">Vladimir Rastseluev</a> */ @RunWith(Arquillian.class) @RunAsClient public class DriverCfgMetricUnitTestCase extends JCAMetrictsTestBase { @BeforeClass public static void before() { setBaseAddress("jdbc-driver", "name"); } @Test public void testDriverAttributes() throws Exception { setModel("complex-driver.xml"); assertEquals("name", readAttribute(baseAddress, "driver-name").asString()); assertEquals("org.h2.jdbcx.JdbcDataSource", readAttribute(baseAddress, "driver-xa-datasource-class-name").asString()); removeDs(); } @Test public void testEmptyDriver() throws Exception { setModel("empty-driver.xml"); assertEquals("name", readAttribute(baseAddress, "driver-name").asString()); removeDs(); } @Test(expected = Exception.class) public void testDriverWoName() throws Exception { setBadModel("wrong-wo-name-driver.xml"); } @Test(expected = Exception.class) public void testDriverWithNoName() throws Exception { setBadModel("wrong-empty-name-driver.xml"); } @Test(expected = Exception.class) public void test2DriverClasses() throws Exception { setBadModel("wrong-2-driver-classes.xml"); } @Test(expected = Exception.class) public void test2DSClasses() throws Exception { setBadModel("wrong-2-ds-classes-driver.xml"); } @Test(expected = Exception.class) public void test2XADSClasses() throws Exception { setBadModel("wrong-2-xa-ds-classes-driver.xml"); } }
2,991
33
126
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/metrics/RaCfgMetricUnitTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.metrics; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.List; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.connector.subsystems.resourceadapters.Namespace; import org.jboss.as.connector.subsystems.resourceadapters.ResourceAdapterSubsystemParser; import org.jboss.as.test.shared.FileUtils; import org.jboss.dmr.ModelNode; import org.junit.Test; import org.junit.runner.RunWith; /** * Resource adapters configuration and metrics unit test. * * @author <a href="mailto:[email protected]">Vladimir Rastseluev</a> */ @RunWith(Arquillian.class) @RunAsClient public class RaCfgMetricUnitTestCase extends JCAMetrictsTestBase { public static void setBaseAddress(String rar) { baseAddress = new ModelNode(); baseAddress.add("subsystem", "resource-adapters"); baseAddress.add("resource-adapter", rar); } // @After - called after each test private void removeRa() throws Exception { removeDs(); } // @Before - called from each test /* * Load data source model, stored in specified file to the configuration */ protected void setModel(String modelName) throws Exception { setBaseAddress(modelName + ".rar"); String xml = FileUtils.readFile(RaCfgMetricUnitTestCase.class, "ra/" + modelName + ".xml"); List<ModelNode> operations = xmlToModelOperations(xml, Namespace.RESOURCEADAPTERS_1_0.getUriString(), new ResourceAdapterSubsystemParser()); executeOperation(operationListToCompositeOperation(operations)); } @Test public void testAttributes() throws Exception { setModel("simple"); ModelNode address1 = baseAddress.clone(); address1.add("connection-definitions", "name1"); address1.protect(); assertTrue(readAttribute(address1, "use-ccm").asBoolean()); assertTrue(readAttribute(address1, "use-java-context").asBoolean()); ModelNode address2 = baseAddress.clone(); address2.add("admin-objects", "Name3"); address2.protect(); assertTrue(readAttribute(address2, "use-java-context").asBoolean()); removeRa(); } @Test public void testEmpty() throws Exception { setModel("empty"); assertEquals("empty.rar", readAttribute(baseAddress, "archive").asString()); removeRa(); } @Test(expected = Exception.class) public void test2Archives() throws Exception { setBadModel("wrong-2-archives"); } @Test(expected = Exception.class) public void testNoArchives() throws Exception { setBadModel("wrong-no-archives"); } @Test public void test2DiffConfProp() throws Exception { setModel("2-diff-conf-prop"); ModelNode address1 = baseAddress.clone(); address1.add("config-properties", "name1"); address1.protect(); assertEquals("value1", readAttribute(address1, "value").asString()); ModelNode address2 = baseAddress.clone(); address2.add("config-properties", "name2"); address2.protect(); assertEquals("value2", readAttribute(address2, "value").asString()); removeRa(); } @Test(expected = Exception.class) public void testConfPropWithEqualNames() throws Exception { setBadModel("wrong-equal-conf-prop"); } // no excepton sent because it's like omit the tag @Test public void testEmptyTrans() throws Exception { setBadModel("wrong-empty-trans"); } @Test(expected = Exception.class) public void testWrongTrans() throws Exception { setBadModel("wrong-trans"); } @Test(expected = Exception.class) public void testWrong2Trans() throws Exception { setBadModel("wrong-2-trans"); } @Test(expected = Exception.class) public void testWrongXAPoolWithTrans() throws Exception { setBadModel("wrong-xa-pool-trans"); } @Test(expected = Exception.class) public void testWrongPoolWithXATrans() throws Exception { setBadModel("wrong-pool-xa-trans"); } @Test(expected = Exception.class) public void test2Pools() throws Exception { setBadModel("wrong-2-pools"); } @Test(expected = Exception.class) public void test2XaPools() throws Exception { setBadModel("wrong-2-xa-pools"); } @Test(expected = Exception.class) public void testPoolAndXaPool() throws Exception { setBadModel("wrong-pool-and-xa-pool"); } @Test(expected = Exception.class) public void testMinPoolSize() throws Exception { setBadModel("wrong-min-pool-size"); } @Test(expected = Exception.class) public void testMaxPoolSize() throws Exception { setBadModel("wrong-max-pool-size"); } @Test(expected = Exception.class) public void testMinGtMaxPoolSize() throws Exception { setBadModel("wrong-min-max-pool-size"); } @Test public void testBoolPresProperties() throws Exception { setModel("bool-pres-properties"); ModelNode address1 = baseAddress.clone(); address1.add("connection-definitions", "name1"); address1.protect(); assertTrue(readAttribute(address1, "interleaving").asBoolean()); assertTrue(readAttribute(address1, "no-tx-separate-pool").asBoolean()); assertTrue(readAttribute(address1, "wrap-xa-resource").asBoolean()); assertFalse(readAttribute(address1, "pad-xid").asBoolean()); assertFalse(readAttribute(address1, "same-rm-override").isDefined()); try { readAttribute(address1, "same-rm-override").asBoolean(); fail("Got boolean value of undefined parameter"); } catch (Exception e) { //Expected } finally { removeRa(); } } @Test public void testBoolPresPropertiesSet() throws Exception { setModel("bool-pres-properties-set"); ModelNode address1 = baseAddress.clone(); address1.add("connection-definitions", "name1"); address1.protect(); assertTrue(readAttribute(address1, "interleaving").asBoolean()); assertTrue(readAttribute(address1, "no-tx-separate-pool").asBoolean()); assertTrue(readAttribute(address1, "no-recovery").asBoolean()); removeRa(); } @Test public void testBoolPresPropertiesUnset() throws Exception { setModel("bool-pres-properties-unset"); ModelNode address1 = baseAddress.clone(); address1.add("connection-definitions", "name1"); address1.protect(); assertFalse(readAttribute(address1, "interleaving").asBoolean()); assertFalse(readAttribute(address1, "no-tx-separate-pool").asBoolean()); assertFalse(readAttribute(address1, "no-recovery").asBoolean()); removeRa(); } @Test(expected = Exception.class) public void testSecurity1() throws Exception { setBadModel("wrong-security-1"); } @Test(expected = Exception.class) public void testSecurity2() throws Exception { setBadModel("wrong-security-2"); } @Test(expected = Exception.class) public void testSecurity3() throws Exception { setBadModel("wrong-security-3"); } @Test(expected = Exception.class) public void testSecurity4() throws Exception { setBadModel("wrong-security-4"); } @Test(expected = Exception.class) public void test2SecurityDomains() throws Exception { setBadModel("wrong-2-security-domains"); } @Test(expected = Exception.class) public void testFlushStrategy() throws Exception { setBadModel("wrong-flush-strategy"); } @Test(expected = Exception.class) public void testNegBlckgTmt() throws Exception { setBadModel("wrong-blck-tmt"); } @Test(expected = Exception.class) public void testNegIdleTmt() throws Exception { setBadModel("wrong-idle-tmt"); } @Test(expected = Exception.class) public void testNegAllocRetry() throws Exception { setBadModel("wrong-alloc-retry"); } @Test(expected = Exception.class) public void testNegAllocRetryWait() throws Exception { setBadModel("wrong-alloc-retry-wait"); } @Test(expected = Exception.class) public void testNegXaResTmt() throws Exception { setBadModel("wrong-xa-res-tmt"); } @Test(expected = Exception.class) public void testNegBckgValid() throws Exception { setBadModel("wrong-bckg-tmt"); } @Test(expected = Exception.class) public void testRecoverPlugin() throws Exception { setBadModel("wrong-recover-plugin"); } @Test(expected = Exception.class) public void testConDefWoClass() throws Exception { setBadModel("wrong-2-con-def-wo-class"); } @Test(expected = Exception.class) public void testAoWoClass() throws Exception { setBadModel("wrong-2-ao-wo-class"); } }
10,210
32.588816
109
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/metrics/JCAMetrictsTestBase.java
package org.jboss.as.test.integration.jca.metrics; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.INCLUDE_RUNTIME; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import java.util.List; import org.jboss.as.connector.subsystems.datasources.DataSourcesExtension; import org.jboss.as.connector.subsystems.datasources.Namespace; import org.jboss.as.test.integration.management.jca.DsMgmtTestBase; import org.jboss.as.test.shared.FileUtils; import org.jboss.dmr.ModelNode; import org.junit.Assert; /** * @author Stuart Douglas */ public abstract class JCAMetrictsTestBase extends DsMgmtTestBase { //@Before - called from each test /* * Load data source model, stored in specified file to the configuration */ protected void setModel(String filename) throws Exception { String xml = FileUtils.readFile(JCAMetrictsTestBase.class, "data-sources/" + filename); List<ModelNode> operations = xmlToModelOperations(xml, Namespace.CURRENT.getUriString(), new DataSourcesExtension.DataSourceSubsystemParser()); executeOperation(operationListToCompositeOperation(operations)); } /* * Bad model must throw an Exception during setModel methos call. To work around wrong test case * removeDs() method is added. */ protected void setBadModel(String filename) throws Exception { setModel(filename); removeDs(); } protected void testStatistics(String configFile) throws Exception { setModel(configFile); try { final ModelNode poolAddress = new ModelNode().set(baseAddress); poolAddress.add("statistics", "pool"); ModelNode operation = new ModelNode(); operation.get(OP).set("read-resource"); operation.get(OP_ADDR).set(poolAddress); operation.get(INCLUDE_RUNTIME).set(true); ModelNode result = executeOperation(operation); Assert.assertTrue("ActiveCount", result.hasDefined("ActiveCount")); final ModelNode jdbcAddress = new ModelNode().set(baseAddress); jdbcAddress.add("statistics", "jdbc"); operation.get(OP_ADDR).set(jdbcAddress); result = executeOperation(operation); Assert.assertTrue("PreparedStatementCacheAccessCount", result.hasDefined("PreparedStatementCacheAccessCount")); } finally { removeDs(); } } }
2,560
36.115942
151
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/metrics/DataSourceCfgMetricUnitTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.metrics; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; /** * Datasource configuration and metrics unit test. * * @author <a href="mailto:[email protected]">Vladimir Rastseluev</a> */ @RunWith(Arquillian.class) @RunAsClient public class DataSourceCfgMetricUnitTestCase extends JCAMetrictsTestBase { @BeforeClass public static void before() { setBaseAddress("data-source", "DS"); } @Test public void testDefaultDsAttributes() throws Exception { setModel("basic-attributes.xml"); assertTrue(readAttribute(baseAddress, "use-ccm").asBoolean()); assertTrue(readAttribute(baseAddress, "jta").asBoolean()); assertTrue(readAttribute(baseAddress, "use-java-context").asBoolean()); assertFalse(readAttribute(baseAddress, "spy").asBoolean()); removeDs(); } @Test(expected = Exception.class) public void testDsWithNoDriver() throws Exception { setBadModel("wrong-no-driver.xml"); } @Test(expected = Exception.class) public void testDsWithWrongTransactionIsolationType() throws Exception { setBadModel("wrong-transaction-isolation-type.xml"); } @Test public void testValidationDefaultProperties() throws Exception { setModel("validation-properties.xml"); assertFalse(readAttribute(baseAddress, "use-fast-fail").asBoolean()); removeDs(); } @Test(expected = Exception.class) public void testWrongValidationProperties() throws Exception { setBadModel("wrong-validation-properties.xml"); } @Test public void testTimeoutDefaultProperties() throws Exception { setModel("timeout-properties.xml"); assertFalse(readAttribute(baseAddress, "set-tx-query-timeout").asBoolean()); removeDs(); } @Test(expected = Exception.class) public void testWrongBlckgTimeoutProperty() throws Exception { setBadModel("wrong-blckg-timeout-property.xml"); } @Test(expected = Exception.class) public void testWrongIdleMinsProperty() throws Exception { setBadModel("wrong-idle-mins-property.xml"); } @Test(expected = Exception.class) public void testWrongAllocRetryProperty() throws Exception { setBadModel("wrong-alloc-retry-property.xml"); } @Test(expected = Exception.class) public void testWrongAllocRetryWaitProperty() throws Exception { setBadModel("wrong-alloc-retry-wait-property.xml"); } @Test public void testStatementDefaultProperties() throws Exception { setModel("statement-properties.xml"); assertEquals("NOWARN", readAttribute(baseAddress, "track-statements").asString()); assertFalse(readAttribute(baseAddress, "share-prepared-statements").asBoolean()); removeDs(); } @Test(expected = Exception.class) public void testWrongTrckStmtProperty() throws Exception { setBadModel("wrong-trck-stmt-property.xml"); } @Test(expected = Exception.class) public void testWrongStmtCacheSizeProperty() throws Exception { setBadModel("wrong-stmt-cache-size-property.xml"); } @Test(expected = Exception.class) public void testWrongFlushStrategyProperty() throws Exception { setBadModel("wrong-flush-strategy-property.xml"); } @Test(expected = Exception.class) public void testWrongMinPoolSizeProperty() throws Exception { setBadModel("wrong-min-pool-size-property.xml"); } @Test(expected = Exception.class) public void testWrongMaxPoolSizeProperty() throws Exception { setBadModel("wrong-max-pool-size-property.xml"); } @Test(expected = Exception.class) public void testWrongMaxLessMinPoolSizeProperty() throws Exception { setBadModel("wrong-max-less-min-pool-size-property.xml"); } @Test public void testStatistics() throws Exception { super.testStatistics("basic-attributes.xml"); } }
5,289
34.033113
90
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/tracer/StatelessBeanRemote.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.tracer; import jakarta.ejb.Remote; /** * @author Ondra Chaloupka <[email protected]> */ @Remote public interface StatelessBeanRemote { void insertToDB(); void createTable(); }
1,259
36.058824
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/tracer/LogHandlerCreationSetup.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.tracer; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REMOVE; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import java.io.File; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FILE; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.LOGGER; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FILE_HANDLER; import org.jboss.as.arquillian.api.ServerSetupTask; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.integration.management.ManagementOperations; import org.jboss.dmr.ModelNode; /** * Adding new log file handler wich is then bound to a logger with specific category. * * @author Ondra Chaloupka <[email protected]> */ public class LogHandlerCreationSetup implements ServerSetupTask { public static String JCA_LOG_FILE_PARAM = "jca-server.log"; public static final String SERVER_LOG_DIR_PARAM = "jboss.server.log.dir"; public static String SERVER_LOG_DIR_VALUE; private static final String HANDLER_NAME = "jca-log-handler"; private static final String LOGGER_CATEGORY_VALUE = "org.jboss.jca.core.tracer"; private static final ModelNode LOGGING_ADDRESS = new ModelNode() .add(SUBSYSTEM, "logging"); private static final ModelNode FILE_HANDLER_ADDRESS = new ModelNode() .set(LOGGING_ADDRESS) .add(FILE_HANDLER, HANDLER_NAME); private static final ModelNode LOGGER_ADDRESS = new ModelNode() .set(LOGGING_ADDRESS) .add(LOGGER, LOGGER_CATEGORY_VALUE); static { LOGGING_ADDRESS.protect(); FILE_HANDLER_ADDRESS.protect(); LOGGER_ADDRESS.protect(); } @Override public void setup(ManagementClient managementClient, String containerId) throws Exception { // /subsystem=logging/file-handler=jca-log-handler:add(append=false, file={relative-to=jboss.server.log.dir, path=jca-server.log}) ModelNode fileHandler = new ModelNode(); fileHandler.get(OP).set(ADD); fileHandler.get(OP_ADDR).set(FILE_HANDLER_ADDRESS); ModelNode file = new ModelNode(); file.get("relative-to").set(SERVER_LOG_DIR_PARAM); file.get("path").set(JCA_LOG_FILE_PARAM); fileHandler.get(FILE).set(file); fileHandler.get("append").set("false"); ManagementOperations.executeOperation(managementClient.getControllerClient(), fileHandler); // /subsystem=logging/logger=org.jboss.jca.core.tracer:add(category=org.jboss.jca.core.tracer, level=TRACE, handlers=[jca-log-handler]) ModelNode logger = new ModelNode(); logger.get(OP).set(ADD); logger.get(OP_ADDR).set(LOGGER_ADDRESS); logger.get("category").set(LOGGER_CATEGORY_VALUE); logger.get("level").set("TRACE"); ModelNode handlers = new ModelNode() .add(HANDLER_NAME); logger.get("handlers").set(handlers); ManagementOperations.executeOperation(managementClient.getControllerClient(), logger); ModelNode getLogDir = new ModelNode(); getLogDir.get(OP).set("resolve-expression"); getLogDir.get("expression").set("${" + SERVER_LOG_DIR_PARAM + "}"); SERVER_LOG_DIR_VALUE = ManagementOperations .executeOperation(managementClient.getControllerClient(), getLogDir).asString(); } @Override public void tearDown(ManagementClient managementClient, String containerId) throws Exception { ModelNode logger = new ModelNode(); logger.get(OP).set(REMOVE); logger.get(OP_ADDR).set(LOGGER_ADDRESS); ManagementOperations.executeOperation(managementClient.getControllerClient(), logger); ModelNode fileHandler = new ModelNode(); fileHandler.get(OP).set(REMOVE); fileHandler.get(OP_ADDR).set(FILE_HANDLER_ADDRESS); ManagementOperations.executeOperation(managementClient.getControllerClient(), fileHandler); new File(SERVER_LOG_DIR_VALUE, JCA_LOG_FILE_PARAM).delete(); } }
5,401
44.016667
143
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/tracer/StatelessBean.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.tracer; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; import jakarta.annotation.Resource; import jakarta.ejb.Stateless; import jakarta.ejb.TransactionAttribute; import jakarta.ejb.TransactionAttributeType; import javax.sql.DataSource; import org.jboss.logging.Logger; /** * @author Ondra Chaloupka <[email protected]> */ @Stateless public class StatelessBean implements StatelessBeanRemote { private static final Logger log = Logger.getLogger(StatelessBean.class); private static final String table = "tracer_table"; private static final String column = "id"; @Resource private DataSource ds; public void insertToDB() { String sql = String.format("INSERT INTO %s (%s) VALUES (%s)", table, column, 1); executeUpdate(sql); log.debugf("sql '%s' executed", sql); } @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public void createTable() { String sql = String.format("CREATE TABLE IF NOT EXISTS %s (%s int)", table, column); executeUpdate(sql); log.debugf("sql '%s' executed", sql); } private void executeUpdate(String sql) { Connection conn = null; try { conn = ds.getConnection(); Statement statement = conn.createStatement(); statement.executeUpdate(sql); } catch (Exception e) { throw new RuntimeException("Can't run sql command '" + sql + "'", e); } finally { if(conn != null) { try { conn.close(); } catch (SQLException e) { // ignore } } } } }
2,779
33.320988
92
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/tracer/TracerEnableTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.tracer; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Hashtable; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.integration.management.ManagementOperations; import org.jboss.as.test.shared.ServerReload; import org.jboss.as.test.shared.SnapshotRestoreSetupTask; import org.jboss.dmr.ModelNode; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * @author Ondra Chaloupka <[email protected]> */ @RunWith(Arquillian.class) @RunAsClient @ServerSetup({ TracerEnableTestCase.TracerEnableSetup.class, LogHandlerCreationSetup.class }) public class TracerEnableTestCase { private static final String ARCHIVE_NAME = "tracer-enable"; @Deployment public static JavaArchive deploy() throws Exception { return ShrinkWrap.create(JavaArchive.class, ARCHIVE_NAME + ".jar") .addClasses(StatelessBean.class, StatelessBeanRemote.class); } @Test public void tracerEnabled() throws NamingException, IOException { final Hashtable<String, Object> jndiProps = new Hashtable<String, Object>(); jndiProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); final Context ctx = new InitialContext(jndiProps); StatelessBeanRemote bean = (StatelessBeanRemote) ctx.lookup( "ejb:/" + ARCHIVE_NAME + "/" + StatelessBean.class.getSimpleName() + "!" + StatelessBeanRemote.class.getName()); bean.createTable(); bean.insertToDB(); File logFile = new File(LogHandlerCreationSetup.SERVER_LOG_DIR_VALUE, LogHandlerCreationSetup.JCA_LOG_FILE_PARAM); Assert.assertTrue("Log file " + logFile + " should exist", logFile.exists()); String logContent = new String(Files.readAllBytes(Paths.get(logFile.getPath())), StandardCharsets.UTF_8); Assert.assertTrue("Log file " + logFile + " has to contain org.jboss.jca.core.tracer.Tracer", logContent.contains("org.jboss.jca.core.tracer.Tracer")); Assert.assertTrue("Log file " + logFile + " has to contain IJTRACER-ExampleDS", logContent.contains("IJTRACER-ExampleDS")); } static final class TracerEnableSetup extends SnapshotRestoreSetupTask { private static final ModelNode TRACER_ADDRESS = new ModelNode() .add(SUBSYSTEM, "jca") .add("tracer", "tracer"); @Override public void doSetup(ManagementClient managementClient, String containerId) throws Exception { ModelNode operation = new ModelNode(); operation.get(OP).set(ADD); operation.get(OP_ADDR).set(TRACER_ADDRESS); operation.get("enabled").set("true"); ManagementOperations.executeOperation(managementClient.getControllerClient(), operation); ServerReload.executeReloadAndWaitForCompletion(managementClient, 30_000); } } }
4,827
43.703704
124
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/flushing/FlushOperationsTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.flushing; import java.io.FilePermission; import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.ReflectPermission; import java.sql.Connection; import java.sql.SQLException; import java.util.List; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.IntStream; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.sql.DataSource; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.dmr.ModelNode; import org.jboss.jca.adapters.jdbc.WrappedConnection; import org.jboss.remoting3.security.RemotingPermission; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import static org.jboss.as.controller.client.helpers.ClientConstants.ADD; import static org.jboss.as.controller.client.helpers.ClientConstants.OP; import static org.jboss.as.controller.client.helpers.ClientConstants.OPERATION_HEADERS; import static org.jboss.as.controller.client.helpers.ClientConstants.OP_ADDR; import static org.jboss.as.controller.client.helpers.ClientConstants.OUTCOME; import static org.jboss.as.controller.client.helpers.ClientConstants.REMOVE_OPERATION; import static org.jboss.as.controller.client.helpers.ClientConstants.SUBSYSTEM; import static org.jboss.as.controller.client.helpers.ClientConstants.SUCCESS; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; /** * Test for flush operations on data source pools: * - flush-all-connection-in-pool * - flush-idle-connection-in-pool * - flush-invalid-connection-in-pool * - flush-gracefully-connection-in-pool * <p> * Everything is tested with allow-multiple-users=true. * <p> * For testing whether a pooled connection is really closed, we check whether the underlying connection is closed. * * @author Jan Martiska */ @RunWith(Arquillian.class) public class FlushOperationsTestCase { @Deployment public static JavaArchive deployment() { final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "flush-operations.jar"); archive.addClass(FlushOperationsTestCase.class); archive.addAsManifestResource( new StringAsset( "Dependencies: org.jboss.as.controller-client, " + "org.jboss.as.controller, " + "org.jboss.dmr, " + "org.jboss.ironjacamar.jdbcadapters, " + "org.jboss.remoting\n"), "MANIFEST.MF"); archive.addAsManifestResource(createPermissionsXmlAsset( // ModelControllerClient needs the following new RemotingPermission("createEndpoint"), new RemotingPermission("connect"), // flushInvalidConnectionsInPool needs the following new RuntimePermission("accessDeclaredMembers"), new ReflectPermission("suppressAccessChecks"), new FilePermission(System.getProperty("jboss.inst") + "/standalone/tmp/auth/*", "read") ), "permissions.xml"); return archive; } @ArquillianResource private ManagementClient managementClient; private PathAddress dsAddress; private String dsName; private String dsJndiName; private DataSource dataSource; private List<Connection> connectionList; private List<Connection> physicalConnectionList; @Before public void createDatasource() throws Exception { dsName = java.util.UUID.randomUUID().toString(); dsAddress = PathAddress.pathAddress(SUBSYSTEM, "datasources").append("data-source", dsName); dsJndiName = "java:/" + dsName; final ModelNode createDsOp = new ModelNode(); createDsOp.get(OP).set(ADD); createDsOp.get(OP_ADDR).set(dsAddress.toModelNode()); createDsOp.get("jndi-name").set(dsJndiName); createDsOp.get("valid-connection-checker-class-name") .set("org.jboss.jca.adapters.jdbc.extensions.novendor.JDBC4ValidConnectionChecker"); createDsOp.get("driver-name").set("h2"); createDsOp.get("allow-multiple-users").set(true); createDsOp.get("connection-url").set("jdbc:h2:mem:test42"); executeAndAssertSuccess(createDsOp); dataSource = getDataSourceInstanceFromJndi(); } /** * After each test: * - close all connections in case that some remained open * - delete the data source */ @After public void cleanup() throws Exception { if (connectionList != null) { connectionList.forEach(this::closeIfNecessary); connectionList = null; } final ModelNode removeOp = new ModelNode(); removeOp.get(OP).set(REMOVE_OPERATION); removeOp.get(OP_ADDR).set(dsAddress.toModelNode()); removeOp.get(OPERATION_HEADERS, ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART).set(true); executeAndAssertSuccess(removeOp); } /** * Obtain 6 connections. * Return connections 0,1,2 to the pool. * Flush all connections. * All connections, especially 3,4,5; should be closed after the flush. */ @Test public void flushAllConnectionsInPool() throws NamingException, SQLException, IOException { initConnections(6); connectionList.get(0).close(); connectionList.get(1).close(); connectionList.get(2).close(); runDataSourceOperationAndAssertSuccess("flush-all-connection-in-pool"); for (int i = 0; i < connectionList.size(); i++) { Assert.assertTrue("Connection #" + i + " should be flushed", physicalConnectionList.get(i).isClosed()); } } /** * Obtain 2 connections. * Return connections 0 to the pool. * Flush all connections gracefully. * Check that only connections 0 is closed while 1 remains open. * Return connections 3,4,5 to the pool. * Check all connections 3,4,5 were closed now. */ @Test public void flushGracefullyConnectionsInPool() throws Exception { initConnections(6); connectionList.get(0).close(); connectionList.get(1).close(); connectionList.get(2).close(); runDataSourceOperationAndAssertSuccess("flush-gracefully-connection-in-pool"); Assert.assertTrue("Connection 0 should get destroyed immediately because it is idle", physicalConnectionList.get(0).isClosed()); Assert.assertTrue("Connection 1 should get destroyed immediately because it is idle", physicalConnectionList.get(1).isClosed()); Assert.assertTrue("Connection 2 should get destroyed immediately because it is idle", physicalConnectionList.get(2).isClosed()); Assert.assertFalse("Connection 3 should not get destroyed immediately because it is not idle", physicalConnectionList.get(3).isClosed()); Assert.assertFalse("Connection 4 should not get destroyed immediately because it is not idle", physicalConnectionList.get(4).isClosed()); Assert.assertFalse("Connection 5 should not get destroyed immediately because it is not idle", physicalConnectionList.get(5).isClosed()); connectionList.get(3).close(); connectionList.get(4).close(); connectionList.get(5).close(); for (int i = 0; i < connectionList.size(); i++) { Assert.assertTrue("Connection #" + i + " should be flushed", physicalConnectionList.get(i).isClosed()); } } /** * Obtain 6 connections. * Return connections 0,1,2 to the pool. * Run flush-idle-connections-in-pool * Check that only the physical connections corresponding to handles 0,1,2 were destroyed. */ @Test public void flushIdleConnectionsInPool() throws Exception { initConnections(6); connectionList.get(0).close(); connectionList.get(1).close(); connectionList.get(2).close(); runDataSourceOperationAndAssertSuccess("flush-idle-connection-in-pool"); Assert.assertTrue("Connection 0 should get destroyed because it is idle", physicalConnectionList.get(0).isClosed()); Assert.assertTrue("Connection 1 should get destroyed because it is idle", physicalConnectionList.get(1).isClosed()); Assert.assertTrue("Connection 2 should get destroyed because it is idle", physicalConnectionList.get(2).isClosed()); Assert.assertFalse("Connection 3 should not get destroyed because it is not idle", physicalConnectionList.get(3).isClosed()); Assert.assertFalse("Connection 4 should not get destroyed because it is not idle", physicalConnectionList.get(4).isClosed()); Assert.assertFalse("Connection 5 should not get destroyed because it is not idle", physicalConnectionList.get(5).isClosed()); } /** * Obtain 3 connections. * Return connections 0,1. * Mark connection 0 as invalid * Run flush-invalid-connection-in-pool * Managed connection of connection 0 should be flushed * Managed connection of connection 1 should NOT be flushed because the connection was not marked invalid * Managed connection of connection 2 should NOT be flushed because the connection was not idle */ @Test public void flushInvalidConnectionsInPool() throws Exception { initConnections(3); connectionList.get(0).close(); connectionList.get(1).close(); // make connection 0 invalid somehow - for example, hack its session field to null // this only works with H2 final Field sessionField = physicalConnectionList.get(0).getClass().getDeclaredField("session"); try { sessionField.setAccessible(true); sessionField.set(physicalConnectionList.get(0), null); } finally { sessionField.setAccessible(false); } runDataSourceOperationAndAssertSuccess("flush-invalid-connection-in-pool"); Assert.assertTrue("Connection 0 should get destroyed because it is marked invalid", physicalConnectionList.get(0).isClosed()); Assert.assertFalse("Connection 1 should not get destroyed because it is valid", physicalConnectionList.get(1).isClosed()); Assert.assertFalse("Connection 2 should not get destroyed because it is not idle", physicalConnectionList.get(2).isClosed()); } /** * Creates a number of connections using the tested data source. * Stores the connections into a list for reference. */ public void initConnections(int count) { connectionList = IntStream.range(0, count) .mapToObj(i -> connectionSupplier.apply(dataSource)) .collect(Collectors.toList()); physicalConnectionList = connectionList .stream() .map(this::getUnderlyingConnection) .collect(Collectors.toList()); } public void executeAndAssertSuccess(ModelNode op) throws IOException { final ModelNode result = managementClient.getControllerClient().execute(op); if (!result.get(OUTCOME).asString().equals(SUCCESS)) { Assert.fail("Operation failed: " + result.toJSONString(true)); } } public void runDataSourceOperationAndAssertSuccess(String operationName) throws IOException { final ModelNode op = new ModelNode(); op.get(OP).set(operationName); op.get(OP_ADDR).set(dsAddress.toModelNode()); executeAndAssertSuccess(op); } public DataSource getDataSourceInstanceFromJndi() throws NamingException { return (DataSource)new InitialContext().lookup(dsJndiName); } public Function<DataSource, Connection> connectionSupplier = (dataSource -> { try { return dataSource.getConnection("sa", ""); } catch (SQLException e) { throw new RuntimeException(e); } }); public void closeIfNecessary(Connection connection) { try { if (!connection.isClosed()) { connection.close(); } } catch (SQLException e) { e.printStackTrace(); } } public Connection getUnderlyingConnection(Connection handle) { try { return ((WrappedConnection)handle).getUnderlyingConnection(); } catch (SQLException e) { throw new RuntimeException(e); } } }
14,249
40.066282
114
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/statistics/DataSourceJdbcStatisticsTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.statistics; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import static org.junit.Assert.fail; import java.sql.Connection; import java.sql.PreparedStatement; import jakarta.annotation.Resource; import javax.sql.DataSource; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.integration.jca.JcaMgmtBase; import org.jboss.as.test.integration.jca.JcaMgmtServerSetupTask; import org.jboss.as.test.integration.management.base.AbstractMgmtTestBase; import org.jboss.as.test.integration.management.base.ContainerResourceMgmtTestBase; import org.jboss.as.test.integration.management.util.MgmtOperationException; import org.jboss.dmr.ModelNode; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.staxmapper.XMLElementReader; import org.jboss.staxmapper.XMLElementWriter; import org.junit.Test; import org.junit.runner.RunWith; /** * JBQA-6456 Test jdbc statistics of data sources * * @author <a href="[email protected]">Vladimir Rastseluev</a> */ @RunWith(Arquillian.class) @ServerSetup(DataSourceJdbcStatisticsTestCase.TestCaseSetup.class) public class DataSourceJdbcStatisticsTestCase { static final String jndiDs = "java:jboss/datasources/StatDS"; static final String jndiXaDs = "java:jboss/datasources/StatXaDS"; static class TestCaseSetup extends JcaMgmtServerSetupTask { ModelNode dsAddress; ModelNode dsXaAddress; @Override public void doSetup(final ManagementClient managementClient) throws Exception { try { dsAddress = createDataSource(false, jndiDs); dsXaAddress = createDataSource(true, jndiXaDs); StringBuffer sb = cleanStats(dsAddress).append(cleanStats(dsXaAddress)); if (sb.length() > 0) { fail(sb.toString()); } } catch (Throwable e) { removeDss(); throw new Exception(e); } } public void removeDss() { try { remove(dsAddress); reload(); } catch (Throwable e) { } try { remove(dsXaAddress); reload(); } catch (Throwable e) { } } /** * Creates data source and return its node address * * @param xa - should be data source XA? * @param jndiName of data source * @return ModelNode - address of data source node * @throws Exception */ private ModelNode createDataSource(boolean xa, String jndiName) throws Exception { ModelNode address = new ModelNode(); address.add(SUBSYSTEM, "datasources"); address.add((xa ? "xa-" : "") + "data-source", jndiName); address.protect(); ModelNode operation = new ModelNode(); operation.get(OP).set(ADD); operation.get(OP_ADDR).set(address); operation.get("jndi-name").set(jndiName); operation.get("driver-name").set("h2"); operation.get("enabled").set("false"); if (!xa) { operation.get("connection-url").set("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"); } operation.get("prepared-statements-cache-size").set(3); operation.get("user-name").set("sa"); operation.get("password").set("sa"); executeOperation(operation); if (xa) { final ModelNode xaDatasourcePropertiesAddress = address.clone(); xaDatasourcePropertiesAddress.add("xa-datasource-properties", "URL"); xaDatasourcePropertiesAddress.protect(); final ModelNode xaDatasourcePropertyOperation = new ModelNode(); xaDatasourcePropertyOperation.get(OP).set("add"); xaDatasourcePropertyOperation.get(OP_ADDR).set(xaDatasourcePropertiesAddress); xaDatasourcePropertyOperation.get("value").set("jdbc:h2:mem:test"); executeOperation(xaDatasourcePropertyOperation); } operation = new ModelNode(); operation.get(OP).set("write-attribute"); operation.get("name").set("enabled"); operation.get("value").set(true); operation.get(OP_ADDR).set(address); executeOperation(operation); reload(); return address; } /** * Cleans jdbc statistics of data source node * * @param ModelNode address of data source node * @return StringBuffer, contains error message, if operation fails * @throws Exception */ public StringBuffer cleanStats(ModelNode address) throws Exception { ModelNode statAddress = getStatAddr(address); executeOnNode(address, "flush-all-connection-in-pool"); executeOnNode(statAddress, "clear-statistics"); return assertStatisticsSet(false, statAddress); } /** * Checks, if some parameters are set on data source statistics node * * @param yes - should be parameters set? * @param statisticNode - address, where to check * @return StringBuffer, contains error message, if operation fails * @throws Exception */ public StringBuffer assertStatisticsSet(boolean yes, ModelNode statisticNode) throws Exception { StringBuffer sb = new StringBuffer(); String[] params = {"PreparedStatementCacheAccessCount", // The number of times that the statement cache was // accessed "PreparedStatementCacheAddCount", // The number of statements added to the statement cache "PreparedStatementCacheCurrentSize", // The number of prepared and callable statements currently cached in // the statement cache "PreparedStatementCacheDeleteCount", // The number of statements discarded from the cache "PreparedStatementCacheHitCount" // The number of times that statements from the cache were used }; for (String param : params) { if ((getStatisticsAttribute(param, statisticNode) == 0) == yes) { sb.append("\nAttribute " + param + " is " + (yes ? "not " : "") + "set"); } } if (sb.length() > 0) { sb.insert(1, "Address:" + statisticNode.toString()); } return sb; } /** * Creates address of statistics jdbc node from address of data source node * * @param address of data source node * @return address of jdbc statistics node */ public ModelNode getStatAddr(ModelNode address) { return address.clone().add("statistics", "jdbc"); } } @Resource(mappedName = jndiDs) DataSource ds; @Resource(mappedName = jndiXaDs) DataSource xaDs; /** * Define the deployment * * @return The deployment archive */ @Deployment public static JavaArchive createDeployment() throws Exception { JavaArchive ja = ShrinkWrap.create(JavaArchive.class, "stat.jar"); ja.addClasses(DataSourceJdbcStatisticsTestCase.class, MgmtOperationException.class, XMLElementReader.class, XMLElementWriter.class, AbstractMgmtTestBase.class, JcaMgmtServerSetupTask.class, JcaMgmtBase.class, ContainerResourceMgmtTestBase.class); return ja; } /** * Helps to test statistics of data source, tries to get prepared statement from cache * * @param d - DataSource to test * @throws Exception */ public void statisticsTest(DataSource d) throws Exception { Connection c = d.getConnection(); for (int i = 1; i <= 5; i++) { PreparedStatement s = c.prepareStatement("select " + i); s.execute(); s.close(); } for (int i = 5; i > 0; i--) { PreparedStatement s = c.prepareStatement("select " + i); s.execute(); s.close(); } c.close(); } @Test public void testDs() throws Exception { statisticsTest(ds); } @Test public void testXaDs() throws Exception { statisticsTest(xaDs); } }
9,934
38.268775
157
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/statistics/SleepServlet.java
package org.jboss.as.test.integration.jca.statistics; import org.jboss.logging.Logger; import jakarta.annotation.Resource; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import javax.sql.DataSource; import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; @SuppressWarnings("serial") @WebServlet(name = "sleep", urlPatterns = {"/sleep/"}, loadOnStartup = 1) public class SleepServlet extends HttpServlet { private Logger LOGGER = Logger.getLogger("SleepServlet"); @Resource(lookup = "java:jboss/datasources/ExampleDS") private DataSource dataSource; @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Connection con = null; try { dataSource.getConnection(); LOGGER.debug("## SLEEP START"); Thread.sleep(3000L); LOGGER.debug("## SLEEP END"); } catch (Exception e) { LOGGER.debug("Exception occured " + e.getMessage()); } finally { try { con.close(); } catch (Exception ee) {} } response.setContentType("text/plain"); final PrintWriter writer = response.getWriter(); writer.write("Servlet result OK"); writer.close(); } }
1,491
30.083333
82
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/statistics/IronJacamarDeploymentStatisticsTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.statistics; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DEPLOYMENT; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jboss.arquillian.container.test.api.Deployer; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.dmr.ModelNode; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * Resource adapter statistics testCase * * @author <a href="mailto:[email protected]">Vladimir Rastseluev</a> */ @RunWith(Arquillian.class) @RunAsClient public class IronJacamarDeploymentStatisticsTestCase extends JcaStatisticsBase { static final String pack = "org.jboss.as.test.integration.jca.rar"; static final String fact = "java:jboss/ConnectionFactory"; @ArquillianResource Deployer deployer; public static ResourceAdapterArchive createDeployment(String deploymentName) throws Exception { ResourceAdapterArchive raa = ShrinkWrap.create(ResourceAdapterArchive.class, "archive" + deploymentName + ".rar"); JavaArchive ja = ShrinkWrap.create(JavaArchive.class, deploymentName + ".jar"); ja.addPackage(pack); raa.addAsLibrary(ja); raa.addAsManifestResource(IronJacamarDeploymentStatisticsTestCase.class.getPackage(), "ra.xml", "ra.xml"); raa.addAsManifestResource(IronJacamarDeploymentStatisticsTestCase.class.getPackage(), "ironjacamar" + deploymentName + ".xml", "ironjacamar.xml"); return raa; } @Deployment(name = "1", managed = false) public static ResourceAdapterArchive first() throws Exception { return createDeployment("1"); } @Deployment(name = "2", managed = false) public static ResourceAdapterArchive second() throws Exception { return createDeployment("2"); } @Deployment(name = "3", managed = false) public static ResourceAdapterArchive third() throws Exception { return createDeployment("3"); } public ModelNode prepareTest(String name) throws Exception { ModelNode address = new ModelNode(); String arch = "archive" + name + ".rar"; address.add(DEPLOYMENT, arch) .add(SUBSYSTEM, "resource-adapters") .add("ironjacamar", "ironjacamar") .add("resource-adapter", arch) .add("connection-definitions", fact + name); deployer.deploy(name); enableStats(name, fact + name); return address; } private void enableStats(String name, String cdName) throws Exception { String arch = "archive" + name + ".rar"; ModelNode statAddress = new ModelNode(); statAddress.add(DEPLOYMENT, arch) .add(SUBSYSTEM, "resource-adapters") .add("ironjacamar", "ironjacamar") .add("resource-adapter", arch) .add("connection-definitions", cdName) .add("statistics", "pool"); statAddress.protect(); ModelNode operation = new ModelNode(); operation.get(OP).set("write-attribute"); operation.get(OP_ADDR).set(statAddress); operation.get("name").set("statistics-enabled"); operation.get("value").set(true); executeOperation(operation); } @Test public void testOneConnection() throws Exception { ModelNode mn = prepareTest("1"); testStatistics(mn); testStatisticsDouble(mn); deployer.undeploy("1"); } @Test public void testTwoConnections() throws Exception { ModelNode mn = prepareTest("1"); ModelNode mn1 = prepareTest("2"); testStatistics(mn); testStatisticsDouble(mn); testStatistics(mn1); testStatisticsDouble(mn1); testInterference(mn, mn1); testInterference(mn1, mn); deployer.undeploy("2"); deployer.undeploy("1"); } @Test public void testTwoConnectionsInOneRa() throws Exception { ModelNode mn = prepareTest("3"); ModelNode mn1 = getAnotherConnection(mn); enableStats("3", mn1.get(4).get("connection-definitions").asString()); testStatistics(mn); testStatisticsDouble(mn); testStatistics(mn1); testStatisticsDouble(mn1); testInterference(mn, mn1); testInterference(mn1, mn); deployer.undeploy("3"); } @Test public void testTwoConnectionsInOneRaPlusOneInOther() throws Exception { ModelNode mn = prepareTest("3"); ModelNode mn1 = getAnotherConnection(mn); enableStats("3", mn1.get(4).get("connection-definitions").asString()); ModelNode mn2 = prepareTest("1"); testStatistics(mn); testStatisticsDouble(mn); testStatistics(mn1); testStatisticsDouble(mn1); testStatistics(mn2); testStatisticsDouble(mn2); testInterference(mn, mn2); testInterference(mn2, mn); testInterference(mn2, mn1); testInterference(mn1, mn2); deployer.undeploy("1"); deployer.undeploy("3"); } private ModelNode getAnotherConnection(ModelNode mn) { ModelNode another = mn.clone(); String newValue = mn.get(4).get("connection-definitions").asString(); int n = 0; Pattern p = Pattern.compile("[0-9]+"); Matcher m = p.matcher(newValue); while (m.find()) { n = Integer.parseInt(m.group()); } ++n; another.get(4).get("connection-definitions").set(fact + n); return another; } @Override public ModelNode translateFromConnectionToStatistics(ModelNode connectionNode) { ModelNode statNode = new ModelNode(); statNode.add(DEPLOYMENT, connectionNode.get(0).get(DEPLOYMENT).asString()); statNode.add(SUBSYSTEM, "resource-adapters"); statNode.add("ironjacamar", "ironjacamar"); statNode.add(connectionNode.get(3)); statNode.add("connection-definitions", connectionNode.get(4).get("connection-definitions").asString()); statNode.add("statistics", "pool"); return statNode; } }
7,736
36.926471
154
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/statistics/DataSourceMultipleConnStatsServerSetupTask.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.statistics; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.operations.common.Util; import org.jboss.as.test.shared.ServerReload; import org.jboss.as.test.integration.security.common.CoreUtils; import org.jboss.as.test.shared.SnapshotRestoreSetupTask; import org.jboss.dmr.ModelNode; import java.util.List; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_HEADERS; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ROLLBACK_ON_RUNTIME_FAILURE; import static org.jboss.as.test.integration.management.util.ModelUtil.createOpNode; /** * * Server setup task for the test case DataSourceMultipleConnStatsTestCase. * Enables statistics and sets min/max pool size on the ExampleDS datasource. * * @author Daniel Cihak */ public class DataSourceMultipleConnStatsServerSetupTask extends SnapshotRestoreSetupTask { @Override public void doSetup(ManagementClient managementClient, String s) throws Exception { ModelNode enableStatsOp = createOpNode("subsystem=datasources/data-source=ExampleDS", ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION); enableStatsOp.get(ModelDescriptionConstants.NAME).set("statistics-enabled"); enableStatsOp.get(ModelDescriptionConstants.VALUE).set(true); ModelNode maxPoolSizeOp = createOpNode("subsystem=datasources/data-source=ExampleDS", ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION); maxPoolSizeOp.get(ModelDescriptionConstants.NAME).set("max-pool-size"); maxPoolSizeOp.get(ModelDescriptionConstants.VALUE).set(1); ModelNode minPoolSizeOp = createOpNode("subsystem=datasources/data-source=ExampleDS", ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION); minPoolSizeOp.get(ModelDescriptionConstants.NAME).set("min-pool-size"); minPoolSizeOp.get(ModelDescriptionConstants.VALUE).set(1); ModelNode updateOp = Util.createCompositeOperation(List.of(enableStatsOp, maxPoolSizeOp, minPoolSizeOp)); updateOp.get(OPERATION_HEADERS, ROLLBACK_ON_RUNTIME_FAILURE).set(false); updateOp.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true); CoreUtils.applyUpdate(updateOp, managementClient.getControllerClient()); ServerReload.reloadIfRequired(managementClient); } }
3,594
48.246575
147
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/statistics/DataSourcePoolStatisticsTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.statistics; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.shared.ServerSnapshot; import org.jboss.dmr.ModelNode; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; /** * Data source statistics testCase * * @author <a href="mailto:[email protected]">Vladimir Rastseluev</a> */ @RunWith(Arquillian.class) @RunAsClient public class DataSourcePoolStatisticsTestCase extends JcaStatisticsBase { static int dsCount = 0; static int xaDsCount = 0; private ModelNode getDsAddress(int count, boolean xa) { ModelNode address = new ModelNode(); address.add(SUBSYSTEM, "datasources"); address.add((xa ? "xa-" : "") + "data-source", getJndi(count, xa)); address.protect(); return address; } private ModelNode createDataSource(boolean xa, int minPoolSize, int maxPoolSize, boolean prefill) throws Exception { ModelNode address; String jndiName; if (xa) { xaDsCount++; jndiName = getJndi(xaDsCount, xa); address = getDsAddress(xaDsCount, xa); } else { dsCount++; jndiName = getJndi(dsCount, xa); address = getDsAddress(dsCount, xa); } ModelNode operation = new ModelNode(); operation.get(OP).set(ADD); operation.get(OP_ADDR).set(address); operation.get("jndi-name").set(jndiName); operation.get("driver-name").set("h2"); operation.get("enabled").set("false"); if (!xa) { operation.get("connection-url").set("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"); } operation.get("min-pool-size").set(minPoolSize); operation.get("max-pool-size").set(maxPoolSize); operation.get("pool-prefill").set(prefill); operation.get("user-name").set("sa"); operation.get("password").set("sa"); executeOperation(operation); if (xa) { final ModelNode xaDatasourcePropertiesAddress = address.clone(); xaDatasourcePropertiesAddress.add("xa-datasource-properties", "URL"); xaDatasourcePropertiesAddress.protect(); final ModelNode xaDatasourcePropertyOperation = new ModelNode(); xaDatasourcePropertyOperation.get(OP).set("add"); xaDatasourcePropertyOperation.get(OP_ADDR).set(xaDatasourcePropertiesAddress); xaDatasourcePropertyOperation.get("value").set("jdbc:h2:mem:test"); executeOperation(xaDatasourcePropertyOperation); } operation = new ModelNode(); operation.get(OP).set("write-attribute"); operation.get("name").set("enabled"); operation.get("value").set(true); operation.get(OP_ADDR).set(address); executeOperation(operation); reload(); return address; } private AutoCloseable snapshot; @Before public void snapshot() { snapshot = ServerSnapshot.takeSnapshot(getManagementClient()); } @After public void closeDataSources() throws Exception { snapshot.close(); snapshot = null; dsCount = 0; xaDsCount = 0; } public String getJndi(int count, boolean xa) { return "java:/datasources/" + (xa ? "Xa" : "") + "Ds" + String.valueOf(count); } @Test public void testOneDs() throws Exception { ModelNode ds1 = createDataSource(false, 0, 20, false); testStatistics(ds1); testStatisticsDouble(ds1); } @Test public void testTwoDs() throws Exception { ModelNode ds1 = createDataSource(false, 0, 10, false); ModelNode ds2 = createDataSource(false, 0, 6, true); testStatistics(ds1); testStatistics(ds2); testStatisticsDouble(ds1); testStatisticsDouble(ds2); testInterference(ds1, ds2); testInterference(ds2, ds1); } @Test public void testOneXaDs() throws Exception { ModelNode ds1 = createDataSource(true, 0, 10, true); testStatistics(ds1); testStatisticsDouble(ds1); } @Test public void testTwoXaDs() throws Exception { ModelNode ds1 = createDataSource(true, 0, 1, false); ModelNode ds2 = createDataSource(true, 0, 1, true); testStatistics(ds1); testStatistics(ds2); testStatisticsDouble(ds1); testStatisticsDouble(ds2); testInterference(ds1, ds2); testInterference(ds2, ds1); } @Test public void testXaPlusDs() throws Exception { ModelNode ds1 = createDataSource(false, 0, 3, false); ModelNode ds2 = createDataSource(true, 0, 4, true); testStatistics(ds1); testStatistics(ds2); testStatisticsDouble(ds1); testStatisticsDouble(ds2); testInterference(ds1, ds2); testInterference(ds2, ds1); } @Override public ModelNode translateFromConnectionToStatistics(ModelNode connectionNode) { ModelNode statNode = connectionNode.clone(); statNode.add("statistics", "pool"); return statNode; } }
6,602
33.570681
120
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/statistics/ResourceAdapterStatisticsTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.statistics; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jboss.arquillian.container.test.api.Deployer; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.dmr.ModelNode; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive; import org.junit.After; import org.junit.AfterClass; import org.junit.Test; import org.junit.runner.RunWith; /** * Resource adapter statistics testCase * * @author <a href="mailto:[email protected]">Vladimir Rastseluev</a> */ @RunWith(Arquillian.class) @RunAsClient public class ResourceAdapterStatisticsTestCase extends JcaStatisticsBase { static int jndiCount = 0; static int archiveCount = 0; static final String pack = "org.jboss.as.test.integration.jca.rar"; static final String fact = "java:jboss/ConnectionFactory"; static final String shortFact = "jboss/ConnectionFactory"; @ArquillianResource Deployer deployer; @AfterClass public static void tearDown() { jndiCount = 0; } @After public void closeAndUndeploy() { String name; while (archiveCount > 0) { name = getArchiveName(archiveCount--); try { deployer.undeploy(name); } finally { try { removeRa(name); } catch (Exception e) { } } } } private void removeRa(String name) throws Exception { remove(getRaAddress(name + ".rar")); } private ModelNode getRaAddress(String name) { ModelNode address = new ModelNode(); address.add(SUBSYSTEM, "resource-adapters"); address.add("resource-adapter", name); address.protect(); return address; } private String getArchiveName(int count) { return "archive" + count; } private ModelNode prepareTest(boolean doubleCF) throws Exception { String archiveName = getArchiveName(++archiveCount); ModelNode address = getRaAddress(archiveName + ".rar"); ModelNode operation = new ModelNode(); operation.get(OP).set("add"); operation.get(OP_ADDR).set(address); operation.get("archive").set(archiveName + ".rar"); executeOperation(operation); int howMany = doubleCF ? 2 : 1; for (int i = 1; i <= howMany; i++) { ModelNode addressConn = address.clone(); String jndiName = getJndiName(++jndiCount); addressConn.add("connection-definitions", jndiName); ModelNode operationConn = new ModelNode(); operationConn.get(OP).set("add"); operationConn.get(OP_ADDR).set(addressConn); operationConn.get("class-name").set(pack + ".MultipleManagedConnectionFactory" + i); operationConn.get("jndi-name").set(jndiName); executeOperation(operationConn); operation = addressConn; } deployer.deploy(archiveName); return operation; } private ModelNode prepareTestShortName() throws Exception { String archiveName = getArchiveName(++archiveCount); ModelNode address = getRaAddress(archiveName + ".rar"); ModelNode operation = new ModelNode(); operation.get(OP).set("add"); operation.get(OP_ADDR).set(address); operation.get("archive").set(archiveName + ".rar"); executeOperation(operation); ModelNode addressConn = address.clone(); int count = ++jndiCount; addressConn.add("connection-definitions", fact + count); ModelNode operationConn = new ModelNode(); operationConn.get(OP).set("add"); operationConn.get(OP_ADDR).set(addressConn); operationConn.get("class-name").set(pack + ".MultipleManagedConnectionFactory1"); operationConn.get("jndi-name").set(shortFact + count); executeOperation(operationConn); operation = addressConn; deployer.deploy(archiveName); return operation; } public static ResourceAdapterArchive createDeployment(String deploymentName) throws Exception { ResourceAdapterArchive raa = ShrinkWrap.create(ResourceAdapterArchive.class, deploymentName + ".rar"); JavaArchive ja = ShrinkWrap.create(JavaArchive.class, deploymentName + ".jar"); ja.addPackage(pack); raa.addAsLibrary(ja); raa.addAsManifestResource(ResourceAdapterStatisticsTestCase.class.getPackage(), "ra.xml", "ra.xml"); return raa; } @Deployment(name = "archive1", managed = false) public static ResourceAdapterArchive first() throws Exception { return createDeployment("archive1"); } @Deployment(name = "archive2", managed = false) public static ResourceAdapterArchive second() throws Exception { return createDeployment("archive2"); } private String getJndiName(int i) { return fact + i; } @Test public void testOneConnection() throws Exception { ModelNode mn = prepareTest(false); testStatistics(mn); testStatisticsDouble(mn); } @Test public void testOneConnectionShortName() throws Exception { ModelNode mn = prepareTestShortName(); testStatistics(mn); testStatisticsDouble(mn); } @Test public void testTwoConnections() throws Exception { ModelNode mn = prepareTest(false); ModelNode mn1 = prepareTest(false); testStatistics(mn); testStatisticsDouble(mn); testStatistics(mn1); testStatisticsDouble(mn1); testInterference(mn, mn1); testInterference(mn1, mn); } @Test public void testTwoConnectionsInOneRa() throws Exception { ModelNode mn = prepareTest(true); ModelNode mn1 = getAnotherConnection(mn); testStatistics(mn); testStatisticsDouble(mn); testStatistics(mn1); testStatisticsDouble(mn1); testInterference(mn, mn1); testInterference(mn1, mn); } @Test public void testTwoConnectionsInOneRaPlusOneInOther() throws Exception { ModelNode mn = prepareTest(true); ModelNode mn1 = getAnotherConnection(mn); ModelNode mn2 = prepareTest(false); testStatistics(mn); testStatisticsDouble(mn); testStatistics(mn1); testStatisticsDouble(mn1); testStatistics(mn2); testStatisticsDouble(mn2); testInterference(mn, mn2); testInterference(mn2, mn); testInterference(mn2, mn1); testInterference(mn1, mn2); } private ModelNode getAnotherConnection(ModelNode mn) { ModelNode another = mn.clone(); String newValue = mn.get(2).get("connection-definitions").asString(); int n = 0; Pattern p = Pattern.compile("[0-9]+"); Matcher m = p.matcher(newValue); while (m.find()) { n = Integer.parseInt(m.group()); } --n; another.get(2).get("connection-definitions").set(fact + n); return another; } @Override public ModelNode translateFromConnectionToStatistics(ModelNode connectionNode) { ModelNode statNode = new ModelNode(); //statNode.add(DEPLOYMENT, connectionNode.get(1).get("resource-adapter").asString()); statNode.add(SUBSYSTEM, "resource-adapters"); statNode.add(connectionNode.get(1)); statNode.add("connection-definitions", connectionNode.get(2).get("connection-definitions").asString()); statNode.add("statistics", "pool"); return statNode; } }
9,185
34.467181
111
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/statistics/DataSourceMultipleConnStatsTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.statistics; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.junit.InSequence; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ContainerResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.controller.operations.common.Util; import org.jboss.as.test.shared.ServerReload; import org.jboss.as.test.integration.common.HttpRequest; import org.jboss.as.test.integration.management.ManagementOperations; import org.jboss.as.test.integration.security.common.CoreUtils; import org.jboss.dmr.ModelNode; import org.jboss.logging.Logger; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Assume; import org.junit.Test; import org.junit.runner.RunWith; import java.net.URL; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import static java.util.concurrent.TimeUnit.SECONDS; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_HEADERS; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ROLLBACK_ON_RUNTIME_FAILURE; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION; import static org.jboss.as.test.integration.management.util.ModelUtil.createOpNode; import static org.junit.Assert.assertEquals; /** * Tests jdbc statistics of a data source with multiple connections. * * Test for [ WFLY-14691 ] * Test for [ WFLY-14789 ] * * @author Daniel Cihak * */ @RunWith(Arquillian.class) @ServerSetup(DataSourceMultipleConnStatsServerSetupTask.class) @RunAsClient public class DataSourceMultipleConnStatsTestCase { private static final String DEPLOYMENT = "DS_STATISTICS"; static final Logger LOGGER = Logger.getLogger(DataSourceMultipleConnStatsTestCase.class); @ContainerResource private ManagementClient managementClient; @ArquillianResource private URL url; private Runnable sleepServletCall = () -> { try { LOGGER.debug("About to call from " + Thread.currentThread().getName()); String response = HttpRequest.get(url.toExternalForm() + "sleep/", 30, SECONDS); LOGGER.debug("Finished call from " + Thread.currentThread().getName()); Assert.assertTrue("Unexpected message from the servlet.", response.contains("Servlet result OK")); } catch (Exception e) { throw new RuntimeException("Servlet request processing failed due to " + e.getMessage()); } }; @Deployment(name = DEPLOYMENT) public static WebArchive appDeployment1() { WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT + ".war"); war.addClass(SleepServlet.class); war.addAsManifestResource(new StringAsset("Dependencies: com.h2database.h2\n"),"MANIFEST.MF"); return war; } /** * Tests the data source statistics attribute MaxWaitCount during waiting requests. * * Test for [ WFLY-14691 ] * * @throws Exception */ @InSequence(1) @Test public void testDataSourceStatistics() throws Exception { ExecutorService executor = Executors.newFixedThreadPool(3); int maxWaitCount = readAttribute("MaxWaitCount").asInt(); assertEquals(0, maxWaitCount); try { executor.execute(sleepServletCall); Thread.sleep(1000L); executor.execute(sleepServletCall); Thread.sleep(1000L); maxWaitCount = readAttribute("MaxWaitCount").asInt(); assertEquals(1, maxWaitCount); executor.execute(sleepServletCall); Thread.sleep(1000L); maxWaitCount = readAttribute("MaxWaitCount").asInt(); assertEquals(2, maxWaitCount); } finally { executor.shutdown(); } } /** * Tests data source statistics after clearStatistics operation was executed. * * Test for [ WFLY-14789 ] * * @throws Exception */ @InSequence(2) @Test public void testClearedDataSourceStatistics() throws Exception { // Disable for now on Windows until WFLY-15336 is sorted Assume.assumeTrue("WFLY-15336", System.getProperty("os.name").equalsIgnoreCase("Linux")); ExecutorService executor = Executors.newFixedThreadPool(1); this.setConnectionPool(); executor.execute(sleepServletCall); Thread.sleep(1000L); this.clearStatistics(); int activeCount = readAttribute("ActiveCount").asInt(); int availableCount = readAttribute("AvailableCount").asInt(); int createdCount = readAttribute("CreatedCount").asInt(); int idleCount = readAttribute("IdleCount").asInt(); int inUseCount = readAttribute("InUseCount").asInt(); assertEquals(5, activeCount); assertEquals(4, availableCount); assertEquals(5, createdCount); assertEquals(4, idleCount); assertEquals(1, inUseCount); } // /subsystem=datasources/data-source=ExampleDS/statistics=pool:read-attribute(name=AvailableCount) private ModelNode readAttribute(String attributeName) throws Exception { ModelNode operation = createOpNode("subsystem=datasources/data-source=ExampleDS/statistics=pool/", READ_ATTRIBUTE_OPERATION); operation.get(NAME).set(attributeName); return ManagementOperations.executeOperation(managementClient.getControllerClient(), operation); } // /subsystem=datasources/data-source=ExampleDS:write-attribute(name=max-pool-size, value=5) // /subsystem=datasources/data-source=ExampleDS:write-attribute(name=min-pool-size, value=5) // /subsystem=datasources/data-source=ExampleDS:write-attribute(name=pool-prefill, value=true) private void setConnectionPool() throws Exception { ModelNode maxPoolSizeOp = createOpNode("subsystem=datasources/data-source=ExampleDS", WRITE_ATTRIBUTE_OPERATION); maxPoolSizeOp.get(NAME).set("max-pool-size"); maxPoolSizeOp.get(VALUE).set(5); ModelNode minPoolSizeOp = createOpNode("subsystem=datasources/data-source=ExampleDS", WRITE_ATTRIBUTE_OPERATION); minPoolSizeOp.get(NAME).set("min-pool-size"); minPoolSizeOp.get(VALUE).set(5); ModelNode prefillOp = createOpNode("subsystem=datasources/data-source=ExampleDS", WRITE_ATTRIBUTE_OPERATION); prefillOp.get(NAME).set("pool-prefill"); prefillOp.get(VALUE).set(true); ModelNode updateOp = Util.createCompositeOperation(List.of(maxPoolSizeOp, minPoolSizeOp, prefillOp)); updateOp.get(OPERATION_HEADERS, ROLLBACK_ON_RUNTIME_FAILURE).set(false); updateOp.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true); CoreUtils.applyUpdate(updateOp, managementClient.getControllerClient()); ServerReload.reloadIfRequired(managementClient); } // /subsystem=datasources/data-source=ExampleDS/statistics=pool/clear-statistics private void clearStatistics() throws Exception { ModelNode operation = createOpNode("subsystem=datasources/data-source=ExampleDS/statistics=pool/", "clear-statistics"); ManagementOperations.executeOperation(managementClient.getControllerClient(), operation); } }
9,036
42.657005
133
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/statistics/JcaStatisticsBase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.statistics; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import org.jboss.as.test.integration.jca.JcaMgmtBase; import org.jboss.dmr.ModelNode; import org.jboss.logging.Logger; /** * Base class for Jakarta Connectors statistics tests * * @author <a href="mailto:[email protected]">Vladimir Rastseluev</a> */ public abstract class JcaStatisticsBase extends JcaMgmtBase { public static final Logger logger = Logger.getLogger(JcaStatisticsBase.class); /** * Default test for pool statistics: flush pool, then test connection * * @param connectionNode - where to test * @param statName - name of statistics parameter * @throws Exception */ protected void testStatistics(ModelNode connectionNode) throws Exception { ModelNode statisticsNode = translateFromConnectionToStatistics(connectionNode); writeAttribute(statisticsNode, "statistics-enabled", "true"); executeOnNode(connectionNode, "flush-all-connection-in-pool"); assertStatisticsShouldBeSet(statisticsNode, false); executeOnNode(connectionNode, "test-connection-in-pool"); assertStatisticsShouldBeSet(statisticsNode, true); } /** * Test for pool statistics: flush pool, then test connection twice * * @param connectionNode - where to test * @param statName - name of statistics parameter * @throws Exception */ protected void testStatisticsDouble(ModelNode connectionNode) throws Exception { ModelNode statisticsNode = translateFromConnectionToStatistics(connectionNode); executeOnNode(connectionNode, "flush-all-connection-in-pool"); executeOnNode(connectionNode, "test-connection-in-pool"); executeOnNode(connectionNode, "test-connection-in-pool"); assertStatisticsShouldBeSet(statisticsNode, true); } /** * Tests, if changing statistics in node1 don't change statistics in other node2 * * @param node1 * @param node2 * @throws Exception */ protected void testInterference(ModelNode node1, ModelNode node2) throws Exception { ModelNode statisticsNode = translateFromConnectionToStatistics(node2); executeOnNode(node1, "flush-all-connection-in-pool"); executeOnNode(node2, "flush-all-connection-in-pool"); resetStatistics(statisticsNode); executeOnNode(node1, "test-connection-in-pool"); assertStatisticsShouldBeSet(statisticsNode, false); } /** * Resets stat counters and enables statistics on given node * * @param statisticsNode * @throws Exception */ protected void resetStatistics(ModelNode statisticsNode) throws Exception { // statistics only reset when the value of "statistics-enabled" actually changes, so switch to false then true writeAttribute(statisticsNode, "statistics-enabled", "false"); writeAttribute(statisticsNode, "statistics-enabled", "true"); } /** * Checks if statistics properties set correctly * * @param node,on which to test * @param yes - should be properties set or not * @throws Exception */ protected void assertStatisticsShouldBeSet(ModelNode node, boolean yes) throws Exception { int avail = getStatisticsAttribute("AvailableCount", node); int active = getStatisticsAttribute("ActiveCount", node); int maxUsed = getStatisticsAttribute("MaxUsedCount", node); logger.trace("Node:" + node.toString() + "\n" + "Available:" + avail + "\n" + "Active:" + active + "\n" + "MaxUsed:" + maxUsed + "\n"); assertTrue(avail > 0); if (yes) { assertTrue("active==" + active, active > 0); assertTrue("maxused==" + maxUsed, maxUsed > 0); } else { assertEquals(0, active); assertEquals(0, maxUsed); } } /** * Subclass should implement this method. It translates address of connection node to the address of statistics node for * chosen subsystem * * @param connection Node * @return statistics Node */ public abstract ModelNode translateFromConnectionToStatistics(ModelNode connectionNode); }
5,342
38.577778
124
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/statistics/xa/XaDataSourcePoolStatisticsTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.statistics.xa; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import static org.junit.Assert.assertEquals; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ContainerResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.test.integration.management.ManagementOperations; import org.jboss.as.test.integration.transactions.TxTestUtil; import org.jboss.as.test.shared.TimeoutUtil; import org.jboss.dmr.ModelNode; import org.jboss.ejb.client.EJBClient; import org.jboss.ejb.client.StatelessEJBLocator; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; /** * XA Data source statistics testCase * * @author [email protected] */ @RunWith(Arquillian.class) @RunAsClient @ServerSetup(XaDataSourceSetupStep.class) public class XaDataSourcePoolStatisticsTestCase { private static final String ARCHIVE_NAME = "xa_transactions"; private static final String APP_NAME = "xa-datasource-pool-statistics-test"; private static final String ATTRIBUTE_XA_COMMIT_COUNT = "XACommitCount"; private static final String ATTRIBUTE_XA_ROLLBACK_COUNT = "XARollbackCount"; private static final String ATTRIBUTE_XA_START_COUNT = "XAStartCount"; private static final int COUNT = 10; @ContainerResource private ManagementClient managementClient; @Deployment public static Archive<?> deploy() { final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, APP_NAME + ".ear"); JavaArchive jar = ShrinkWrap.create(JavaArchive.class, ARCHIVE_NAME + ".jar"); jar.addClasses(TestEntity.class, SLSB1.class, SLSB.class, TimeoutUtil.class); jar.addPackage(TxTestUtil.class.getPackage()); jar.addAsManifestResource(XaDataSourcePoolStatisticsTestCase.class.getPackage(), "persistence.xml", "persistence.xml"); ear.addAsModule(jar); ear.addAsManifestResource(new StringAsset("Dependencies: com.h2database.h2\n"), "MANIFEST.MF"); return ear; } @Before public void beforeTest() throws Exception { // TODO Elytron: Determine how this should be adapted once the transaction client changes are in //final EJBClientTransactionContext localUserTxContext = EJBClientTransactionContext.createLocal(); //EJBClientTransactionContext.setGlobalContext(localUserTxContext); } /** * Tests increasing XACommitCount, XACommitAverageTime and XAStartCount * statistical attributes. */ @Test public void testXACommit() throws Exception { int xaStartCountBefore = readStatisticalAttribute(ATTRIBUTE_XA_START_COUNT); int xaCommitCount = readStatisticalAttribute(ATTRIBUTE_XA_COMMIT_COUNT); assertEquals(ATTRIBUTE_XA_COMMIT_COUNT + " is " + xaCommitCount + " but should be 0", 0, xaCommitCount); SLSB slsb = getBean(); for (int i = 0; i < COUNT; i++) { slsb.commit(); } xaCommitCount = readStatisticalAttribute(ATTRIBUTE_XA_COMMIT_COUNT); int xaStartCountAfter = readStatisticalAttribute(ATTRIBUTE_XA_START_COUNT); int total = xaStartCountBefore + COUNT; assertEquals(ATTRIBUTE_XA_COMMIT_COUNT + " is " + xaCommitCount + " but should be " + COUNT, COUNT, xaCommitCount); assertEquals(ATTRIBUTE_XA_START_COUNT + " is " + xaStartCountAfter + " but should be " + total, total, xaStartCountAfter); } /** * Tests increasing XARollbackCount statistical attribute. */ @Test public void testXARollback() throws Exception { int xaRollbackCount = readStatisticalAttribute(ATTRIBUTE_XA_ROLLBACK_COUNT); assertEquals(ATTRIBUTE_XA_ROLLBACK_COUNT + " is " + xaRollbackCount + " but should be 0", 0, xaRollbackCount); SLSB slsb = getBean(); for (int i = 0; i < COUNT; i++) { slsb.rollback(); } xaRollbackCount = readStatisticalAttribute(ATTRIBUTE_XA_ROLLBACK_COUNT); assertEquals(ATTRIBUTE_XA_ROLLBACK_COUNT + " is " + xaRollbackCount + " but should be " + COUNT, COUNT, xaRollbackCount); } private SLSB getBean() { final StatelessEJBLocator<SLSB> locator = new StatelessEJBLocator<SLSB>(SLSB.class, APP_NAME, ARCHIVE_NAME, SLSB1.class.getSimpleName(), ""); return EJBClient.createProxy(locator); } private ModelNode getStaticticsAddress() { return PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, "datasources"), PathElement.pathElement("xa-data-source", XaDataSourceSetupStep.XA_DATASOURCE_NAME), PathElement.pathElement("statistics", "pool")).toModelNode(); } private int readStatisticalAttribute(String attributeName) throws Exception { return readAttribute(getStaticticsAddress(), attributeName).asInt(); } private ModelNode readAttribute(ModelNode address, String attributeName) throws Exception { ModelNode op = new ModelNode(); op.get(OP).set(READ_ATTRIBUTE_OPERATION); op.get(NAME).set(attributeName); op.get(OP_ADDR).set(address); return ManagementOperations.executeOperation(managementClient.getControllerClient(), op); } }
7,146
43.66875
162
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/statistics/xa/XaDataSourceSetupStep.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.statistics.xa; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.integration.management.util.CLIWrapper; import org.jboss.as.test.shared.SnapshotRestoreSetupTask; /** * Adds xa-data-source before deployment and removes it at the end. * * @author [email protected] * */ class XaDataSourceSetupStep extends SnapshotRestoreSetupTask { public static final String XA_DATASOURCE_NAME = "ExampleXADS"; private CLIWrapper cli; @Override public void doSetup(ManagementClient managementClient, String serverId) throws Exception { initCli(); addXaDatasource(XA_DATASOURCE_NAME); } @Override protected void nonManagementCleanUp() throws Exception { quitCli(); } private void addXaDatasource(String name) { StringBuilder builder = new StringBuilder(); builder.append("xa-data-source add --name="); builder.append(name); builder.append(" --jndi-name=java:jboss/datasources/"); builder.append(name); builder.append(" --driver-name=h2 --user-name=sa --password=sa --statistics-enabled=true --enabled=true"); builder.append(" --xa-datasource-properties={\"URL\"=>\"jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE\"}"); cli.sendLine(builder.toString()); } private void initCli() throws Exception { if (cli == null) { cli = new CLIWrapper(true); } } private void quitCli() throws Exception { try { if (cli != null) cli.quit(); } finally { cli = null; } } }
2,699
35
127
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/statistics/xa/SLSB.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.statistics.xa; import jakarta.ejb.Remote; /** * @author [email protected] */ @Remote public interface SLSB { void commit() throws Exception; void rollback() throws Exception; }
1,259
35
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/statistics/xa/TestEntity.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.statistics.xa; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; /** * @author [email protected] */ @Entity public class TestEntity { @Id @GeneratedValue(strategy = GenerationType.AUTO) public long id; public long getId() { return id; } public void setId(long id) { this.id = id; } }
1,507
30.416667
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/statistics/xa/SLSB1.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.statistics.xa; import jakarta.annotation.Resource; import jakarta.ejb.Stateless; import jakarta.ejb.TransactionManagement; import jakarta.ejb.TransactionManagementType; import jakarta.inject.Inject; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; import jakarta.transaction.TransactionManager; import jakarta.transaction.UserTransaction; import org.jboss.as.test.integration.transactions.TransactionCheckerSingleton; import org.jboss.as.test.integration.transactions.TxTestUtil; /** * @author [email protected] */ @Stateless @TransactionManagement(TransactionManagementType.BEAN) public class SLSB1 implements SLSB { @PersistenceContext(unitName = "testxapu") private EntityManager em; @Resource(name = "java:jboss/TransactionManager") private TransactionManager tm; @Resource private UserTransaction tx; @Inject private TransactionCheckerSingleton checker; @Override public void commit() throws Exception { tx.begin(); TxTestUtil.enlistTestXAResource(tm.getTransaction(), checker); em.persist(new TestEntity()); tx.commit(); } @Override public void rollback() throws Exception { tx.begin(); TxTestUtil.enlistTestXAResource(tm.getTransaction(), checker); em.persist(new TestEntity()); em.flush(); tx.rollback(); } }
2,470
30.679487
78
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/beanvalidation/DisabledValidationTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.beanvalidation; import org.jboss.arquillian.container.test.api.Deployer; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.integration.jca.JcaMgmtBase; import org.jboss.as.test.integration.jca.JcaMgmtServerSetupTask; import org.jboss.as.test.integration.jca.beanvalidation.ra.ValidConnectionFactory; import org.jboss.dmr.ModelNode; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * @author <a href="[email protected]">Vladimir Rastseluev</a> * JBQA-6006 - disabled bean validation */ @RunWith(Arquillian.class) @ServerSetup(DisabledValidationTestCase.DisabledValidationTestCaseSetup.class) @RunAsClient public class DisabledValidationTestCase { static class DisabledValidationTestCaseSetup extends JcaMgmtServerSetupTask { ModelNode bvAddress = subsystemAddress.clone().add("bean-validation", "bean-validation"); @Override protected void doSetup(ManagementClient managementClient) throws Exception { writeAttribute(bvAddress, "enabled", "false"); } } @ArquillianResource Deployer deployer; /** * Define the deployment * * @return The deployment archive */ public static ResourceAdapterArchive createDeployment(String ij) throws Exception { String deploymentName = (ij != null ? ij : "valid"); ResourceAdapterArchive raa = ShrinkWrap.create(ResourceAdapterArchive.class, deploymentName + ".rar"); JavaArchive ja = ShrinkWrap.create(JavaArchive.class, deploymentName + ".jar"); ja.addPackage(ValidConnectionFactory.class.getPackage()).addClasses(DisabledValidationTestCase.class, JcaMgmtServerSetupTask.class, JcaMgmtBase.class); raa.addAsLibrary(ja); raa.addAsManifestResource(DisabledValidationTestCase.class.getPackage(), "ra.xml", "ra.xml").addAsManifestResource( DisabledValidationTestCase.class.getPackage(), "ironjacamar" + (ij != null ? "-" + ij : "") + ".xml", "ironjacamar.xml"); return raa; } public void test(String deployment) { deployer.deploy(deployment); deployer.undeploy(deployment); } @Deployment(name = "wrong-ao", managed = false) public static ResourceAdapterArchive createAODeployment() throws Exception { return createDeployment("wrong-ao"); } @Test public void testWrongAO() { test("wrong-ao"); } @Deployment(name = "wrong-cf", managed = false) public static ResourceAdapterArchive createCfDeployment() throws Exception { return createDeployment("wrong-cf"); } @Test public void testWrongCf() { test("wrong-cf"); } @Deployment(name = "wrong-ra", managed = false) public static ResourceAdapterArchive createRaDeployment() throws Exception { return createDeployment("wrong-ra"); } @Test public void testWrongRA() { test("wrong-ra"); } }
4,466
35.917355
123
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/beanvalidation/NegativeValidationASTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.beanvalidation; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.util.List; import java.util.Set; import jakarta.resource.spi.ActivationSpec; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.test.integration.jca.beanvalidation.ra.ValidActivationSpec; import org.jboss.as.test.integration.jca.beanvalidation.ra.ValidConnectionFactory; import org.jboss.as.test.integration.jca.beanvalidation.ra.ValidMessageEndpoint; import org.jboss.as.test.integration.jca.beanvalidation.ra.ValidMessageEndpointFactory; import org.jboss.jca.core.spi.mdr.MetadataRepository; import org.jboss.jca.core.spi.rar.Endpoint; import org.jboss.jca.core.spi.rar.MessageListener; import org.jboss.jca.core.spi.rar.ResourceAdapterRepository; import org.jboss.msc.service.ServiceContainer; import org.jboss.msc.service.ServiceController; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * @author <a href="[email protected]">Vladimir Rastseluev</a> JBQA-5906 */ @RunWith(Arquillian.class) public class NegativeValidationASTestCase { @ArquillianResource ServiceContainer serviceContainer; /** * Define the deployment * * @return The deployment archive */ @Deployment public static ResourceAdapterArchive createDeployment() throws Exception { String deploymentName = "valid.rar"; ResourceAdapterArchive raa = ShrinkWrap.create(ResourceAdapterArchive.class, deploymentName); JavaArchive ja = ShrinkWrap.create(JavaArchive.class, "valid.jar"); ja.addPackage(ValidConnectionFactory.class.getPackage()).addClasses(NegativeValidationASTestCase.class); raa.addAsLibrary(ja); raa.addAsManifestResource(NegativeValidationASTestCase.class.getPackage(), "ra-wrong-as-property.xml", "ra.xml") .addAsManifestResource(NegativeValidationASTestCase.class.getPackage(), "ironjacamar.xml", "ironjacamar.xml") .addAsManifestResource( new StringAsset("Dependencies: javax.inject.api,org.jboss.as.connector \n"), "MANIFEST.MF"); return raa; } @Test(expected = Exception.class) public void testRegistryConfiguration() throws Throwable { ServiceController<?> controller = serviceContainer.getService(ConnectorServices.RA_REPOSITORY_SERVICE); assertNotNull(controller); ResourceAdapterRepository repository = (ResourceAdapterRepository) controller.getValue(); assertNotNull(repository); Set<String> ids = repository.getResourceAdapters(jakarta.jms.MessageListener.class); assertNotNull(ids); //assertEquals(1, ids.size()); String piId = ids.iterator().next(); assertNotNull(piId); Endpoint endpoint = repository.getEndpoint(piId); assertNotNull(endpoint); List<MessageListener> listeners = repository.getMessageListeners(piId); assertNotNull(listeners); assertEquals(1, listeners.size()); MessageListener listener = listeners.get(0); ActivationSpec as = listener.getActivation().createInstance(); assertNotNull(as); assertNotNull(as.getResourceAdapter()); ValidActivationSpec vas = (ValidActivationSpec) as; ValidMessageEndpoint me = new ValidMessageEndpoint(); ValidMessageEndpointFactory mef = new ValidMessageEndpointFactory(me); endpoint.activate(mef, vas); endpoint.deactivate(mef, vas); } @Test public void testMetadataConfiguration() throws Throwable { ServiceController<?> controller = serviceContainer.getService(ConnectorServices.IRONJACAMAR_MDR); assertNotNull(controller); MetadataRepository repository = (MetadataRepository) controller.getValue(); assertNotNull(repository); Set<String> ids = repository.getResourceAdapters(); assertNotNull(ids); //assertEquals(1, ids.size()); String piId = ids.iterator().next(); assertNotNull(piId); assertNotNull(repository.getResourceAdapter(piId)); } }
5,544
39.772059
125
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/beanvalidation/NegativeValidationTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.beanvalidation; import org.jboss.arquillian.container.test.api.Deployer; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.test.integration.jca.beanvalidation.ra.ValidConnectionFactory; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * @author <a href="[email protected]">Vladimir Rastseluev</a> JBQA-5905 */ @RunWith(Arquillian.class) public class NegativeValidationTestCase { @ArquillianResource Deployer deployer; /** * Define the deployment * * @return The deployment archive */ public static ResourceAdapterArchive createDeployment(String ij) throws Exception { String deploymentName = (ij != null ? ij : "valid"); ResourceAdapterArchive raa = ShrinkWrap.create(ResourceAdapterArchive.class, deploymentName + ".rar"); JavaArchive ja = ShrinkWrap.create(JavaArchive.class, deploymentName + ".jar"); ja.addPackage(ValidConnectionFactory.class.getPackage()).addClasses(NegativeValidationTestCase.class); raa.addAsLibrary(ja); raa.addAsManifestResource(NegativeValidationTestCase.class.getPackage(), "ra.xml", "ra.xml") .addAsManifestResource( NegativeValidationTestCase.class.getPackage(), "ironjacamar" + (ij != null ? "-" + ij : "") + ".xml", "ironjacamar.xml"); return raa; } @Deployment(name = "wrong-ao", managed = false) public static ResourceAdapterArchive createAODeployment() throws Exception { return createDeployment("wrong-ao"); } @Test(expected = Exception.class) public void testWrongAO() { deployer.deploy("wrong-ao"); } @Deployment(name = "wrong-cf", managed = false) public static ResourceAdapterArchive createCfDeployment() throws Exception { return createDeployment("wrong-cf"); } @Test(expected = Exception.class) public void testWrongCf() { deployer.deploy("wrong-cf"); } @Deployment(name = "wrong-ra", managed = false) public static ResourceAdapterArchive createRaDeployment() throws Exception { return createDeployment("wrong-ra"); } @Test(expected = Exception.class) public void testWrongRA() { deployer.deploy("wrong-ra"); } }
3,592
36.821053
145
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/beanvalidation/PositiveValidationTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.beanvalidation; import static org.jboss.as.test.shared.PermissionUtils.createPermissionsXmlAsset; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.util.List; import java.util.Set; import jakarta.annotation.Resource; import jakarta.resource.spi.ActivationSpec; import org.hibernate.validator.HibernateValidatorPermission; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.test.integration.jca.beanvalidation.ra.ValidActivationSpec; import org.jboss.as.test.integration.jca.beanvalidation.ra.ValidAdminObjectInterface; import org.jboss.as.test.integration.jca.beanvalidation.ra.ValidConnection; import org.jboss.as.test.integration.jca.beanvalidation.ra.ValidConnectionFactory; import org.jboss.as.test.integration.jca.beanvalidation.ra.ValidMessageEndpoint; import org.jboss.as.test.integration.jca.beanvalidation.ra.ValidMessageEndpointFactory; import org.jboss.jca.core.spi.mdr.MetadataRepository; import org.jboss.jca.core.spi.rar.Endpoint; import org.jboss.jca.core.spi.rar.MessageListener; import org.jboss.jca.core.spi.rar.ResourceAdapterRepository; import org.jboss.msc.service.ServiceContainer; import org.jboss.msc.service.ServiceController; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * @author <a href="[email protected]">Vladimir Rastseluev</a> JBQA-5904 */ @RunWith(Arquillian.class) public class PositiveValidationTestCase { @ArquillianResource ServiceContainer serviceContainer; /** * Define the deployment * * @return The deployment archive */ @Deployment public static ResourceAdapterArchive createDeployment() throws Exception { String deploymentName = "valid.rar"; ResourceAdapterArchive raa = ShrinkWrap.create(ResourceAdapterArchive.class, deploymentName); JavaArchive ja = ShrinkWrap.create(JavaArchive.class, "valid.jar"); ja.addPackage(ValidConnectionFactory.class.getPackage()).addClasses(PositiveValidationTestCase.class); raa.addAsLibrary(ja); raa.addAsManifestResource(PositiveValidationTestCase.class.getPackage(), "ra.xml", "ra.xml") .addAsManifestResource(PositiveValidationTestCase.class.getPackage(), "ironjacamar.xml", "ironjacamar.xml") .addAsManifestResource(new StringAsset("Dependencies: javax.inject.api,org.jboss.as.connector\n"), "MANIFEST.MF"); raa.addAsManifestResource(createPermissionsXmlAsset( HibernateValidatorPermission.ACCESS_PRIVATE_MEMBERS ), "permissions.xml"); return raa; } @Resource(mappedName = "java:jboss/VCF") private ValidConnectionFactory connectionFactory; @Resource(mappedName = "java:jboss/VAO") ValidAdminObjectInterface adminObject; /** * Test configuration * * @throws Throwable Thrown if case of an error */ @Test public void testConfiguration() throws Throwable { assertNotNull("CF not found", connectionFactory); assertNotNull("AO not found", adminObject); ValidConnection con = connectionFactory.getConnection(); assertEquals("admin", adminObject.getAoProperty()); assertEquals(4, con.getResourceAdapterProperty()); assertEquals("prop", con.getManagedConnectionFactoryProperty()); con.close(); } @Test public void testRegistryConfiguration() throws Throwable { ServiceController<?> controller = serviceContainer.getService(ConnectorServices.RA_REPOSITORY_SERVICE); assertNotNull(controller); ResourceAdapterRepository repository = (ResourceAdapterRepository) controller.getValue(); assertNotNull(repository); Set<String> ids = repository.getResourceAdapters(jakarta.jms.MessageListener.class); assertNotNull(ids); String piId = ids.iterator().next(); assertNotNull(piId); Endpoint endpoint = repository.getEndpoint(piId); assertNotNull(endpoint); List<MessageListener> listeners = repository.getMessageListeners(piId); assertNotNull(listeners); assertEquals(1, listeners.size()); MessageListener listener = listeners.get(0); ActivationSpec as = listener.getActivation().createInstance(); assertNotNull(as); assertNotNull(as.getResourceAdapter()); ValidActivationSpec vas = (ValidActivationSpec) as; ValidMessageEndpoint me = new ValidMessageEndpoint(); ValidMessageEndpointFactory mef = new ValidMessageEndpointFactory(me); endpoint.activate(mef, vas); endpoint.deactivate(mef, vas); } @Test public void testMetadataConfiguration() throws Throwable { ServiceController<?> controller = serviceContainer.getService(ConnectorServices.IRONJACAMAR_MDR); assertNotNull(controller); MetadataRepository repository = (MetadataRepository) controller.getValue(); assertNotNull(repository); Set<String> ids = repository.getResourceAdapters(); assertNotNull(ids); String piId = ids.iterator().next(); assertNotNull(piId); assertNotNull(repository.getResourceAdapter(piId)); } }
6,636
39.969136
130
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/beanvalidation/ra/ValidConnectionImpl.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.beanvalidation.ra; /** * Connection implementation * * @author <a href="mailto:[email protected]">Vladimir Rastseluev</a> */ public class ValidConnectionImpl implements ValidConnection { /** * ManagedConnection */ private ValidManagedConnection mc; /** * ManagedConnectionFactory */ private ValidManagedConnectionFactory mcf; /** * Default constructor * * @param mc ManagedConnection * @param mcf ManagedConnectionFactory */ public ValidConnectionImpl(ValidManagedConnection mc, ValidManagedConnectionFactory mcf) { this.mc = mc; this.mcf = mcf; } /** * Call getResourceAdapterProperty * * @return String */ public int getResourceAdapterProperty() { return ((ValidResourceAdapter) mcf.getResourceAdapter()).getRaProperty(); } /** * Call getManagedConnectionFactoryProperty * * @return String */ public String getManagedConnectionFactoryProperty() { return mcf.getCfProperty(); } /** * Close */ public void close() { mc.closeHandle(this); } }
2,228
28.328947
94
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/beanvalidation/ra/ValidGroup.java
package org.jboss.as.test.integration.jca.beanvalidation.ra; import jakarta.validation.groups.Default; public interface ValidGroup extends Default { }
154
18.375
60
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/beanvalidation/ra/ValidResourceAdapter.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.beanvalidation.ra; import java.io.Serializable; import java.util.HashMap; import java.util.Map; import jakarta.resource.ResourceException; import jakarta.resource.spi.ActivationSpec; import jakarta.resource.spi.BootstrapContext; import jakarta.resource.spi.ResourceAdapter; import jakarta.resource.spi.ResourceAdapterInternalException; import jakarta.resource.spi.endpoint.MessageEndpointFactory; import javax.transaction.xa.XAResource; import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotNull; /** * Resource adapter * * @author <a href="mailto:[email protected]">Vladimir Rastseluev</a> */ public class ValidResourceAdapter implements ResourceAdapter, Serializable { /** * */ private static final long serialVersionUID = 1L; /** * property */ @NotNull @Min(3) private Integer raProperty; /** * The activations by activation spec */ private Map<ValidActivationSpec, ValidActivation> activations = new HashMap<ValidActivationSpec, ValidActivation>(); /** * Default constructor */ public ValidResourceAdapter() { } /** * Set property * * @param property The value */ public void setRaProperty(Integer property) { this.raProperty = property; } /** * Get property * * @return The value */ public Integer getRaProperty() { return raProperty; } /** * This is called during the activation of a message endpoint. * * @param endpointFactory A message endpoint factory instance. * @param spec An activation spec JavaBean instance. * @throws jakarta.resource.ResourceException generic exception */ public void endpointActivation(MessageEndpointFactory endpointFactory, ActivationSpec spec) throws ResourceException { ValidActivation activation = new ValidActivation(this, endpointFactory, (ValidActivationSpec) spec); activations.put((ValidActivationSpec) spec, activation); activation.start(); } /** * This is called when a message endpoint is deactivated. * * @param endpointFactory A message endpoint factory instance. * @param spec An activation spec JavaBean instance. */ public void endpointDeactivation(MessageEndpointFactory endpointFactory, ActivationSpec spec) { ValidActivation activation = activations.remove(spec); if (activation != null) { activation.stop(); } } /** * This is called when a resource adapter instance is bootstrapped. * * @param ctx A bootstrap context containing references * @throws jakarta.resource.spi.ResourceAdapterInternalException indicates bootstrap failure. */ public void start(BootstrapContext ctx) throws ResourceAdapterInternalException { } /** * This is called when a resource adapter instance is undeployed or during application server shutdown. */ public void stop() { } /** * This method is called by the application server during crash recovery. * * @param specs An array of ActivationSpec JavaBeans * @return An array of XAResource objects * @throws jakarta.resource.ResourceException generic exception */ public XAResource[] getXAResources(ActivationSpec[] specs) throws ResourceException { return null; } /** * Returns a hash code value for the object. * * @return A hash code value for this object. */ @Override public int hashCode() { return 31 + 7 * raProperty; } /** * Indicates whether some other object is equal to this one. * * @param other The reference object with which to compare. * @return true if this object is the same as the obj argument, false otherwise. */ @Override public boolean equals(Object other) { if (other == null) { return false; } if (other == this) { return true; } if (!(other instanceof ValidResourceAdapter)) { return false; } ValidResourceAdapter obj = (ValidResourceAdapter) other; boolean result = true; if (result) { result = raProperty.equals(obj.getRaProperty()); } return result; } }
5,368
31.737805
122
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/beanvalidation/ra/ValidAdminObjectInterface1.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.beanvalidation.ra; import java.io.Serializable; import jakarta.resource.Referenceable; /** * Admin object * * @author <a href="mailto:[email protected]">Vladimir Rastseluev</a> */ public interface ValidAdminObjectInterface1 extends Referenceable, Serializable { /** * Set property * * @param property The value */ void setAoProperty(String property); /** * Get property * * @return The value */ String getAoProperty(); }
1,560
32.212766
81
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/beanvalidation/ra/ValidConnectionFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.beanvalidation.ra; import java.io.Serializable; import jakarta.resource.Referenceable; import jakarta.resource.ResourceException; /** * Connection factory * * @author <a href="mailto:[email protected]">Vladimir Rastseluev</a> */ public interface ValidConnectionFactory extends Serializable, Referenceable { /** * Get connection from factory * * @return Connection instance * @throws jakarta.resource.ResourceException Thrown if a connection can't be obtained */ ValidConnection getConnection() throws ResourceException; }
1,637
38
90
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/beanvalidation/ra/ValidManagedConnectionFactory1.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.beanvalidation.ra; import java.io.PrintWriter; import java.util.Iterator; import java.util.Set; import jakarta.resource.ResourceException; import jakarta.resource.spi.ConnectionManager; import jakarta.resource.spi.ConnectionRequestInfo; import jakarta.resource.spi.ManagedConnection; import jakarta.resource.spi.ManagedConnectionFactory; import jakarta.resource.spi.ResourceAdapter; import jakarta.resource.spi.ResourceAdapterAssociation; import javax.security.auth.Subject; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; /** * Managed connection factory * * @author <a href="mailto:[email protected]">Vladimir Rastseluev</a> */ public class ValidManagedConnectionFactory1 implements ManagedConnectionFactory, ResourceAdapterAssociation { /** * The serial version UID */ private static final long serialVersionUID = 1L; /** * The resource adapter */ private ResourceAdapter ra; /** * The logwriter */ private PrintWriter logwriter; /** * property */ @NotNull @Size(max = 5) private String cfProperty; /** * Default constructor */ public ValidManagedConnectionFactory1() { } /** * Set property * * @param property The value */ public void setCfProperty(String property) { this.cfProperty = property; } /** * Get property * * @return The value */ public String getCfProperty() { return cfProperty; } /** * Creates a Connection Factory instance. * * @param cxManager ConnectionManager to be associated with created EIS connection factory instance * @return EIS-specific Connection Factory instance or jakarta.resource.cci.ConnectionFactory instance * @throws jakarta.resource.ResourceException Generic exception */ public Object createConnectionFactory(ConnectionManager cxManager) throws ResourceException { return new ValidConnectionFactoryImpl1(this, cxManager); } /** * Creates a Connection Factory instance. * * @return EIS-specific Connection Factory instance or jakarta.resource.cci.ConnectionFactory instance * @throws jakarta.resource.ResourceException Generic exception */ public Object createConnectionFactory() throws ResourceException { throw new ResourceException("This resource adapter doesn't support non-managed environments"); } /** * Creates a new physical connection to the underlying EIS resource manager. * * @param subject Caller's security information * @param cxRequestInfo Additional resource adapter specific connection request information * @return ManagedConnection instance * @throws jakarta.resource.ResourceException generic exception */ public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException { return new ValidManagedConnection1(this); } /** * Returns a matched connection from the candidate set of connections. * * @param connectionSet Candidate connection set * @param subject Caller's security information * @param cxRequestInfo Additional resource adapter specific connection request information * @return ManagedConnection if resource adapter finds an acceptable match otherwise null * @throws jakarta.resource.ResourceException generic exception */ public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException { ManagedConnection result = null; Iterator it = connectionSet.iterator(); while (result == null && it.hasNext()) { ManagedConnection mc = (ManagedConnection) it.next(); if (mc instanceof ValidManagedConnection) { result = mc; } } return result; } /** * Get the log writer for this ManagedConnectionFactory instance. * * @return PrintWriter * @throws jakarta.resource.ResourceException generic exception */ public PrintWriter getLogWriter() throws ResourceException { return logwriter; } /** * Set the log writer for this ManagedConnectionFactory instance. * * @param out PrintWriter - an out stream for error logging and tracing * @throws jakarta.resource.ResourceException generic exception */ public void setLogWriter(PrintWriter out) throws ResourceException { logwriter = out; } /** * Get the resource adapter * * @return The handle */ public ResourceAdapter getResourceAdapter() { return ra; } /** * Set the resource adapter * * @param ra The handle */ public void setResourceAdapter(ResourceAdapter ra) { this.ra = ra; } /** * Returns a hash code value for the object. * * @return A hash code value for this object. */ @Override public int hashCode() { int result = 17; if (cfProperty != null) { result += 31 * result + 7 * cfProperty.hashCode(); } else { result += 31 * result + 7; } return result; } /** * Indicates whether some other object is equal to this one. * * @param other The reference object with which to compare. * @return true if this object is the same as the obj argument, false otherwise. */ @Override public boolean equals(Object other) { if (other == null) { return false; } if (other == this) { return true; } if (!(other instanceof ValidManagedConnectionFactory1)) { return false; } ValidManagedConnectionFactory1 obj = (ValidManagedConnectionFactory1) other; boolean result = true; if (result) { if (cfProperty == null) { result = obj.getCfProperty() == null; } else { result = cfProperty.equals(obj.getCfProperty()); } } return result; } }
7,180
31.940367
135
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/beanvalidation/ra/ValidMessageEndpoint.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.beanvalidation.ra; import java.lang.reflect.Method; import jakarta.jms.Message; import jakarta.jms.MessageListener; import jakarta.resource.spi.endpoint.MessageEndpoint; /** * A simple message endpoint * * @author <a href="mailto:[email protected]>Vladimir Rastseluev</a> */ public class ValidMessageEndpoint implements MessageEndpoint, MessageListener { private Message message; /** * Constructor */ public ValidMessageEndpoint() { } /** * {@inheritDoc} */ public void onMessage(Message message) { this.message = message; } /** * Get the message * * @return The value */ public Message getMessage() { return message; } /** * {@inheritDoc} */ public void afterDelivery() { } /** * {@inheritDoc} */ public void beforeDelivery(Method method) { } /** * {@inheritDoc} */ public void release() { } }
2,050
24.012195
79
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/beanvalidation/ra/ValidActivationSpec.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.beanvalidation.ra; import jakarta.resource.spi.ActivationSpec; import jakarta.resource.spi.InvalidPropertyException; import jakarta.resource.spi.ResourceAdapter; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import org.jboss.logging.Logger; /** * Activation Spec * * @author <a href="mailto:[email protected]">Vladimir Rastseluev</a> */ public class ValidActivationSpec implements ActivationSpec { /** * The logger */ private static Logger log = Logger.getLogger(ValidActivationSpec.class); /** * The resource adapter */ private ResourceAdapter ra; @NotNull private Boolean myBooleanProperty; @NotNull @Size(min = 5) private String myStringProperty; /** * Default constructor */ public ValidActivationSpec() { } /** * This method may be called by a deployment tool to validate the overall activation configuration information provided by * the endpoint deployer. * * @throws InvalidPropertyException indicates invalid onfiguration property settings. */ public void validate() throws InvalidPropertyException { log.trace("validate()"); } /** * @return the myBooleanProperty */ public Boolean isMyBooleanProperty() { return myBooleanProperty; } /** * @param myBooleanProperty the myBooleanProperty to set */ public void setMyStringProperty(String myProperty) { this.myStringProperty = myProperty; } /** * @return the myBooleanProperty */ public String getMyStringProperty() { return myStringProperty; } /** * @param myBooleanProperty the myBooleanProperty to set */ public void setMyBooleanProperty(Boolean myBooleanProperty) { this.myBooleanProperty = myBooleanProperty; } /** * Get the resource adapter * * @return The handle */ public ResourceAdapter getResourceAdapter() { log.trace("getResourceAdapter()"); return ra; } /** * Set the resource adapter * * @param ra The handle */ public void setResourceAdapter(ResourceAdapter ra) { log.trace("setResourceAdapter()"); this.ra = ra; } }
3,368
26.842975
126
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/beanvalidation/ra/ValidConnectionFactoryImpl.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.beanvalidation.ra; import javax.naming.NamingException; import javax.naming.Reference; import jakarta.resource.ResourceException; import jakarta.resource.spi.ConnectionManager; /** * Connection factory implementation * * @author <a href="mailto:[email protected]">Vladimir Rastseluev</a> */ public class ValidConnectionFactoryImpl implements ValidConnectionFactory { /** * The serial version UID */ private static final long serialVersionUID = 1L; /** * Reference */ private Reference reference; /** * ManagedConnectionFactory */ private ValidManagedConnectionFactory mcf; /** * ConnectionManager */ private ConnectionManager connectionManager; /** * Default constructor */ public ValidConnectionFactoryImpl() { } /** * Constructor * * @param mcf ManagedConnectionFactory * @param cxManager ConnectionManager */ public ValidConnectionFactoryImpl(ValidManagedConnectionFactory mcf, ConnectionManager cxManager) { this.mcf = mcf; this.connectionManager = cxManager; } /** * Get connection from factory * * @return Connection instance * @throws jakarta.resource.ResourceException Thrown if a connection can't be obtained */ @Override public ValidConnection getConnection() throws ResourceException { return (ValidConnection) connectionManager.allocateConnection(mcf, null); } /** * Get the Reference instance. * * @return Reference instance * @throws javax.naming.NamingException Thrown if a reference can't be obtained */ @Override public Reference getReference() throws NamingException { return reference; } /** * Set the Reference instance. * * @param reference A Reference instance */ @Override public void setReference(Reference reference) { this.reference = reference; } }
3,062
28.171429
103
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/beanvalidation/ra/ValidConnection1.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.beanvalidation.ra; /** * Connection * * @author <a href="mailto:[email protected]">Vladimir Rastseluev</a> */ public interface ValidConnection1 { /** * getResourceAdapterProperty * * @return String */ int getResourceAdapterProperty(); /** * getManagedConnectionFactoryProperty * * @return String */ String getManagedConnectionFactoryProperty(); /** * Close */ void close(); }
1,533
30.306122
71
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jca/beanvalidation/ra/ValidManagedConnection.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.jca.beanvalidation.ra; import static org.wildfly.common.Assert.checkNotNullParam; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import jakarta.resource.NotSupportedException; import jakarta.resource.ResourceException; import jakarta.resource.spi.ConnectionEvent; import jakarta.resource.spi.ConnectionEventListener; import jakarta.resource.spi.ConnectionRequestInfo; import jakarta.resource.spi.LocalTransaction; import jakarta.resource.spi.ManagedConnection; import jakarta.resource.spi.ManagedConnectionMetaData; import javax.security.auth.Subject; import javax.transaction.xa.XAResource; /** * Managed connection * * @author <a href="mailto:[email protected]">Vladimir Rastseluev</a> */ public class ValidManagedConnection implements ManagedConnection { /** * The logwriter */ private PrintWriter logwriter; /** * ManagedConnectionFactory */ private ValidManagedConnectionFactory mcf; /** * Listeners */ private List<ConnectionEventListener> listeners; /** * Connection */ private Object connection; /** * Default constructor * * @param mcf mcf */ public ValidManagedConnection(ValidManagedConnectionFactory mcf) { this.mcf = mcf; this.logwriter = null; this.listeners = new ArrayList<ConnectionEventListener>(1); this.connection = null; } /** * Creates a new connection handle for the underlying physical connection represented by the ManagedConnection instance. * * @param subject Security context as JAAS subject * @param cxRequestInfo ConnectionRequestInfo instance * @return generic Object instance representing the connection handle. * @throws jakarta.resource.ResourceException generic exception if operation fails */ public Object getConnection(Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException { connection = new ValidConnectionImpl(this, mcf); return connection; } /** * Used by the container to change the association of an application-level connection handle with a ManagedConneciton * instance. * * @param connection Application-level connection handle * @throws jakarta.resource.ResourceException generic exception if operation fails */ public void associateConnection(Object connection) throws ResourceException { } /** * Application server calls this method to force any cleanup on the ManagedConnection instance. * * @throws jakarta.resource.ResourceException generic exception if operation fails */ public void cleanup() throws ResourceException { } /** * Destroys the physical connection to the underlying resource manager. * * @throws jakarta.resource.ResourceException generic exception if operation fails */ public void destroy() throws ResourceException { } /** * Adds a connection event listener to the ManagedConnection instance. * * @param listener A new ConnectionEventListener to be registered */ public void addConnectionEventListener(ConnectionEventListener listener) { checkNotNullParam("listener", listener); listeners.add(listener); } /** * Removes an already registered connection event listener from the ManagedConnection instance. * * @param listener already registered connection event listener to be removed */ public void removeConnectionEventListener(ConnectionEventListener listener) { checkNotNullParam("listener", listener); listeners.remove(listener); } /** * Close handle * * @param handle The handle */ public void closeHandle(ValidConnection handle) { ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED); event.setConnectionHandle(handle); for (ConnectionEventListener cel : listeners) { cel.connectionClosed(event); } } /** * Gets the log writer for this ManagedConnection instance. * * @return Character ourput stream associated with this Managed-Connection instance * @throws jakarta.resource.ResourceException generic exception if operation fails */ public PrintWriter getLogWriter() throws ResourceException { return logwriter; } /** * Sets the log writer for this ManagedConnection instance. * * @param out Character Output stream to be associated * @throws jakarta.resource.ResourceException generic exception if operation fails */ public void setLogWriter(PrintWriter out) throws ResourceException { logwriter = out; } /** * Returns an <code>jakarta.resource.spi.LocalTransaction</code> instance. * * @return LocalTransaction instance * @throws jakarta.resource.ResourceException generic exception if operation fails */ public LocalTransaction getLocalTransaction() throws ResourceException { throw new NotSupportedException("LocalTransaction not supported"); } /** * Returns an <code>javax.transaction.xa.XAresource</code> instance. * * @return XAResource instance * @throws jakarta.resource.ResourceException generic exception if operation fails */ public XAResource getXAResource() throws ResourceException { throw new NotSupportedException("GetXAResource not supported not supported"); } /** * Gets the metadata information for this connection's underlying EIS resource manager instance. * * @return ManagedConnectionMetaData instance * @throws jakarta.resource.ResourceException generic exception if operation fails */ public ManagedConnectionMetaData getMetaData() throws ResourceException { return new ValidManagedConnectionMetaData(); } }
7,003
34.02
124
java