通辽网站建设0475seo,沈阳最新新闻事件今天,百度快照 直接进入网站,wordpress换模板arquillian听到许多好评后#xff0c;我想我会尝试一下Open Liberty 。 在这篇文章中#xff0c;我将讨论以下内容#xff1a; 开放自由的设置 设置JDBC连接 设置Arquillian 测试REST端点 安装开放自由 在撰写本文时#xff0c;我正在使用Open Liberty 18.0.0.1… arquillian 听到许多好评后我想我会尝试一下Open Liberty 。 在这篇文章中我将讨论以下内容 开放自由的设置 设置JDBC连接 设置Arquillian 测试REST端点 安装开放自由 在撰写本文时我正在使用Open Liberty 18.0.0.1并且正在使用Java SE 1.8.0_172PS Keen继续使用Java 9和Java 10但我认为最好等待LTS Java 11。 安装非常容易。 假设我们要创建一个正在运行的服务器名称test 。 首先解压缩您的Open Liberty下载文件。 它将创建目录结构wlp 。 导航到bin目录并运行以下命令 ./server create test 现在服务器名称test已创建。 开始 ./server start test 参数test是服务器的名称。 导航到http://localhost:9080/test以查看上下文根。 停止 ./server stop test 配置server.xml 启动test服务器后将在/usr/servers/test下创建一个目录该目录内有一个名为server.xml文件。 让我们来看看。 ?xml version1.0 encodingUTF-8?
server descriptionnew server!-- Enable features --featureManagerfeaturejsp-2.3/feature/featureManager!-- To access this server from a remote client add a host attribute to the following element, e.g. host* --httpEndpoint iddefaultHttpEndpointhttpPort9080httpsPort9443 /!-- Automatically expand WAR files and EAR files --applicationManager autoExpandtrue/
/server 在本文中我们使用Java EE 7 Web Profile来实现这一点这非常简单甚至不必重新启动服务器。 只需更改featureManager 。 ?xml version1.0 encodingUTF-8?
server descriptionnew server!-- Enable features --featureManagerfeaturewebProfile-7.0/feature/featureManager!-- the rest of the configuration omitted -- 您可以通过查看console.log来检查正在动态加载的功能。 配置JDBC数据源 在server.xml中配置数据源 对于本练习我正在使用MySQL 8.0。 设置MySQL及其配置不在本文的讨论范围之内。 假设我们已经创建了一个新数据库也称为test 。 要设置您的数据源请对server.xml进行以下修改然后重新启动或不必对此不太确定但重新启动没有任何危害。 评论交错。 ?xml version3.0 encodingUTF-8?
server descriptionnew server!-- Enable features --featureManagerfeaturewebProfile-7.0/feature/featureManager!-- Declare the jar files for MySQL access through JDBC. --dataSource idtestDS jndiNamejdbc/testDSjdbcDriver libraryRefMySQLLib/properties databaseNametestserverNamelocalhost portNumber3306userroot passwordP4sswordGoesH3r3//dataSourcelibrary idMySQLLibfile name/home/dwuysan/dev/appservers/wlp/usr/shared/resources/mysql/mysql-connector-java-8.0.11.jar//library!-- Automatically expand WAR files and EAR files --applicationManager autoExpandtrue/
/server persistence.xml OpenLiberty随附有作为JPA Provider捆绑的EclipseLink。 在此示例中我没有配置任何EclipseLink的属性。 ?xml version1.0 encodingUTF-8?
persistence xmlnshttp://xmlns.jcp.org/xml/ns/persistencexmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsdversion2.1persistence-unit nametestPUjta-data-sourcejdbc/testDS/jta-data-source properties/properties/persistence-unit
/persistence 然后您可以通过以下方式在Java EE应用程序中调用它 Stateless
LocalBean
public class LogService {PersistenceContextprivate EntityManager em;public CollectionLog getLogs() {return this.em.createNamedQuery(Log.FIND_ALL, Log.class).getResultList();}
}设置arquillian 在本文中我们将针对正在运行的OpenLiberty服务器实施Arquillian远程测试。 首先将arquillian添加到pom.xml 。 配置pom.xml 这是已修改的pom.xml ?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdid.co.lucyana/groupIdartifactIdtest/artifactIdversion1.0-SNAPSHOT/versionpackagingwar/packagingnametest/namepropertiesendorsed.dir${project.build.directory}/endorsed/endorsed.dirproject.build.sourceEncodingUTF-8/project.build.sourceEncoding/propertiesdependencyManagementdependenciesdependencygroupIdorg.jboss.arquillian/groupIdartifactIdarquillian-bom/artifactIdversion1.4.0.Final/versionscopeimport/scopetypepom/type/dependency/dependencies/dependencyManagementdependencies dependencygroupIdorg.jboss.arquillian.graphene/groupIdartifactIdgraphene-webdriver/artifactIdversion2.3.2/versiontypepom/typescopetest/scope/dependencydependencygroupIdorg.seleniumhq.selenium/groupIdartifactIdselenium-java/artifactIdscopetest/scopeversion3.12.0/version/dependencydependencygroupIdorg.jboss.arquillian.junit/groupIdartifactIdarquillian-junit-container/artifactIdscopetest/scope/dependency dependency!-- Arquillian WebSphere Liberty Profile support --groupIdio.openliberty.arquillian/groupIdartifactIdarquillian-liberty-remote/artifactIdversion1.0.0/versionscopetest/scope/dependencydependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion4.12/versionscopetest/scope/dependencydependencygroupIdjavax/groupIdartifactIdjavaee-web-api/artifactIdversion7.0/versionscopeprovided/scope/dependency/dependenciesbuildpluginsplugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-compiler-plugin/artifactIdversion3.7.0/versionconfigurationsource1.8/sourcetarget1.8/targetcompilerArgumentsendorseddirs${endorsed.dir}/endorseddirs/compilerArguments/configuration/pluginplugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-war-plugin/artifactIdversion3.2.1/versionconfigurationfailOnMissingWebXmlfalse/failOnMissingWebXml/configuration/pluginplugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-dependency-plugin/artifactIdversion3.1.0/versionexecutionsexecutionphasevalidate/phasegoalsgoalcopy/goal/goalsconfigurationoutputDirectory${endorsed.dir}/outputDirectorysilenttrue/silentartifactItemsartifactItemgroupIdjavax/groupIdartifactIdjavaee-endorsed-api/artifactIdversion7.0/versiontypejar/type/artifactItem/artifactItems/configuration/execution/executions/plugin/plugins/build
/project 修改server.xml 这里提供的文档是不言自明的。 请查阅此文档以获取有关如何启用远程测试的更多最新信息。 ?xml version1.0 encodingUTF-8?
server descriptionnew server!-- Enable features --featureManagerfeaturewebProfile-7.0/featurefeaturerestConnector-2.0/feature/featureManager!-- Declare the jar files for MySQL access through JDBC. --dataSource idtestDS jndiNamejdbc/testDSjdbcDriver libraryRefMySQLLib/properties databaseNametest serverNamelocalhost portNumber3306 userroot passwordP4sswordGoesH3r3//dataSourcelibrary idMySQLLibfile name/home/dwuysan/dev/appservers/wlp/usr/shared/resources/mysql/mysql-connector-java-8.0.11.jar//libraryhttpEndpoint httpPort9080 httpsPort9443 iddefaultHttpEndpoint host* /!-- userName and password should also be set in arquillian.xml to these values --quickStartSecurity userNameadmin userPasswordadmin /!-- Enable the keystore --keyStore iddefaultKeyStore passwordpassword /applicationMonitor updateTriggermbean /logging consoleLogLevelINFO /!-- This section is needed to allow upload of files to the dropins directory, the remote container adapter relies on this configuration --remoteFileAccesswriteDir${server.config.dir}/dropins/writeDir/remoteFileAccess!-- Automatically expand WAR files and EAR files --applicationManager autoExpandtrue/
/server 信任服务器即证书 您还需要让客户端信任这些密钥否则您将看到SSL证书信任错误并且需要授予容器适配器写入dropins目录的权限” Liberty-Arquillian 2018 完成上述所有必要的更改后并重新启动服务器请注意在location of your OpenLiberty server/usr/servers/test/resources/security下创建了一个新目录其中test为名称我们最初创建的服务器的数量。 请注意正在创建两个文件 keys.jks和ltpa.keys 。 现在我们对keys.jks感兴趣。 为了能够从NetbeansMaven运行测试JDK必须信任正在运行的OpenLiberty。 检查证书 keytool -list -v -keystore key.jks
Enter keystore password: 此处的password基本上是我们在server.xml中创建的password 尤其是以下行 !-- Enable the keystore --
keyStore iddefaultKeyStore passwordpassword / 因此输入密码输出应如下所示 ***************** WARNING WARNING WARNING *****************
* The integrity of the information stored in your keystore *
* has NOT been verified! In order to verify its integrity, *
* you must provide your keystore password. *
***************** WARNING WARNING WARNING *****************Keystore type: jks
Keystore provider: SUNYour keystore contains 1 entryAlias name: default
Creation date: May 26, 2018
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
Owner: CNlocalhost, OUtest, Oibm, Cus
Issuer: CNlocalhost, OUtest, Oibm, Cus
Serial number: 2a6c5b27
Valid from: Sat May 26 12:24:30 WITA 2018 until: Sun May 26 12:24:30 WITA 2019
Certificate fingerprints:MD5: 63:92:B2:4A:25:E3:BB:3B:96:37:11:C1:A7:25:38:B5SHA1: B6:38:95:88:FC:50:EC:A0:8E:41:4E:DE:B5:D4:8B:85:2E:61:A2:5FSHA256: 9C:7B:6A:FA:46:8C:50:F2:7D:7B:C4:24:4B:15:78:5A:34:25:C8:43:D1:AB:4D:EE:C7:00:4C:AF:30:F5:5C:92
Signature algorithm name: SHA256withRSA
Subject Public Key Algorithm: 2048-bit RSA key
Version: 3Extensions: #1: ObjectId: 2.5.29.14 Criticalityfalse
SubjectKeyIdentifier [
KeyIdentifier [
0000: 88 F2 C2 32 73 73 B6 66 8F FA 42 85 1F 43 A5 AF ...2ss.f..B..C..
0010: 84 33 62 D5 .3b.
]
]*******************************************
******************************************* 接下来导出证书 现在我们需要创建一个.cer 。 使用以下命令 keytool -export -alias default -file testwlp.crt -keystore key.jks
Enter keystore password: 基本上我们将alias证书导出到名为testwlp.crt的文件中。 现在应该创建一个名为testwlp.crt的文件。 最后通过将证书导入JDK cacert来信任该证书 keytool -import -trustcacerts -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -alias testwlp -import -file testwlp.crt PS请注意正如许多专家通过Twitter所指出的那样显然有很多方法可以“信任”服务器。 我确信有更好的方法并且我尽可能不接触任何JDK的文件。 创建arquillian.xml 现在完成了所有这些管道工作让我们相应地添加arquillian.xml 。 ?xml version1.0 encodingUTF-8?
arquillian xmlnshttp://jboss.org/schema/arquillian xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsdengineproperty namedeploymentExportPathtarget/property/enginecontainer qualifierliberty-remote defaulttrueconfigurationproperty namehostNamelocalhost/propertyproperty nameserverNametest/property!-- check the quickStartSecurity on server.xml --property nameusernameadmin/propertyproperty namepasswordadmin/property!-- check the server.xml --property namehttpPort9080/propertyproperty namehttpsPort9443/property /configuration/container extension qualifierwebdriver!--property namebrowserfirefox/property--property nameremoteReusablefalse/property/extension
/arquillian编写REST测试用例 完成所有这些设置后您现在可以编写Arquillian Test用例。 下面是一个针对JAX-RS端点的测试用例的示例请原谅测试用例的简单性这一点是为了说明如何使用Arquillian-remote针对OpenLiberty进行测试 package id.co.lucyana.test.resource;import id.co.lucyana.test.entity.Log;
import id.co.lucyana.test.services.LogService;
import id.co.lucyana.test.util.ApplicationConfig;
import java.net.URL;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.drone.api.annotation.Drone;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ArchivePaths;
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;
import org.openqa.selenium.WebDriver;RunWith(Arquillian.class)
public class LogResourceTest {Droneprivate WebDriver webDriver;Deploymentpublic static JavaArchive createTestArchive() {return ShrinkWrap.create(JavaArchive.class).addClass(Log.class).addClass(LogResource.class).addClass(LogService.class).addClass(ApplicationConfig.class).addAsManifestResource(test-persistence.xml,ArchivePaths.create(persistence.xml));}TestRunAsClientpublic void testLogResource(ArquillianResource URL url) { this.webDriver.get(url.toString() resources/log);String pageSource this.webDriver.getPageSource();System.out.println(RESULT: pageSource);Assert.assertTrue(true);}
}参考资料 DigiCert2018 如何将受信任的根安装到Java cacerts Keystore中 DigiCert于2018年6月20日访问 Liberty-Arquillian2018年 “ Arquillian Liberty远程文档” GitHub。 Inc于2018年6月20日访问 SSLShopper2008年 “最常见的Java Keytool密钥库命令” SSLShopper于2018年6月20日访问 翻译自: https://www.javacodegeeks.com/2018/06/testing-openliberty-arquillian-remote.htmlarquillian