Pages

Sunday, August 10, 2014

Test your WebLogic 12.1.3 enviroment with Robot

Robot Framework is a generic test automation framework which has an easy-to-use tabular test data syntax and it utilizes the keyword-driven testing approach. This means we can write our tests in readable and understandable text.

If we combine this with the REST Management interface of WebLogic 12.1.3 we are able to test every detail of a WebLogic domain configuration and when we combine this with selenium or other Robot plugins we can also test our Web Applications or REST/Web Services.

So after all your provisioning and application deployments actions we can test our new environment in just a few minutes and Administrators or Testers can make or extend these tests without any developer knowledge.

Here is an example of some WebLogic domain tests


The only thing a developer should do, is to use make these test sentences, so called keywords

Here is the matching keyword example


Off course you don't need to use keywords but then you will get something like this. :-)


For this we need to enable the REST Management interface Weblogic 12.1.3 ( WebLogic Console -> Domain -> General -> Advanced -> Enable RESTful Management Services ) and install the robotframework-requests add-on.

Click here for more information about the WebLogic REST management service and you can use Postman ( a Chrome plugin)  to test your REST calls.

Next we can add our tests & keywords in a subfolder.



And run pybot rest_testsuites



With this as output


The detail report 




With the Selenium plugin (robotframework-selenium2library ) we can also test a web application deployed on a WebLogic server. In this example I will use the WebLogic Console application to test the selenium plugin.

run pybot console_testsuites


Our test


The matching resource file with the keywords.



For more information about Robot in combination with WebLogic you can also read the great blogs of my colleague Mark Nelson http://redstack.wordpress.com/tag/robot/

Here you can download the github workspace https://github.com/biemond/robot-weblogic

Enjoy

Thursday, August 7, 2014

Create with WLST a SOA Suite, Service Bus 12.1.3 Domain

When you want to create a 12.1.3 SOA Suite, Service Bus Domain, you have to use the WebLogic config.sh utility.  The 12.1.3 config utility is a big improvement when you compare this to WebLogic 11g. With this I can create some complex cluster configuration without any after configuration.
But if you want to automate the domain creation and use it in your own (provisioning) tool/script then you can use the following scripts to create a normal SOA Suite, Service Bus domain together with BPM, BAM & the Enterprise scheduler options.

Off course!!! use this script only for development, do some intensive testing on this domain and don't use this script in production or acceptance ( use the supported config.sh utility).

The second part of this blog we will create a cluster configuration with a WLST offline script.

Before we can start we need to have a FMW database repository.  You can use the RCU utility ( MDW_HOME/oracle_common/bin/rcu) to create one.

Enable the following options



Here you can also see the improvements in the 12c FMW domain creation like

  • ServerGroups, an easy way of assigning libraries,  applications and datasources to managed servers and clusters. It will auto-detect if a managed server is part of a cluster :-)
  • Service Table Datasource together with the getDatabaseDefaults() function, no need to change all the datasources. It will re-use the RCU configuration data.


Use this to start the creation of our domain.
MDW_HOME/oracle_common/common/bin/wlst.sh soa_domain_1213.py

Here we need to do some extra configuration like

  • Change a few datasources so they will use the Oracle XA driver

WLHOME = '/opt/oracle/middleware12c/wlserver'
DOMAIN = 'soa_domain'
DOMAIN_PATH = '/opt/oracle/wlsdomains/domains/soa_domain'
APP_PATH = '/opt/oracle/wlsdomains/applications/soa_domain'
SERVER_ADDRESS = '10.10.10.21'
LOG_FOLDER = '/var/log/weblogic/'
JSSE_ENABLED = true
DEVELOPMENT_MODE = true
WEBTIER_ENABLED = false
ADMIN_SERVER = 'AdminServer'
ADMIN_USER = 'weblogic'
ADMIN_PASSWORD = 'weblogic1'
JAVA_HOME = '/usr/java/latest'
ADM_JAVA_ARGUMENTS = '-XX:PermSize=256m -XX:MaxPermSize=512m -Xms1024m -Xmx1532m -Dweblogic.Stdout='+LOG_FOLDER+'AdminServer.out -Dweblogic.Stderr='+LOG_FOLDER+'AdminServer_err.out'
OSB_JAVA_ARGUMENTS = '-XX:PermSize=256m -XX:MaxPermSize=512m -Xms1024m -Xmx1024m '
SOA_JAVA_ARGUMENTS = '-XX:PermSize=256m -XX:MaxPermSize=752m -Xms1024m -Xmx1532m '
BAM_JAVA_ARGUMENTS = '-XX:PermSize=256m -XX:MaxPermSize=512m -Xms1024m -Xmx1532m '
SOA_REPOS_DBURL = 'jdbc:oracle:thin:@soadb.example.com:1521/soarepos.example.com'
SOA_REPOS_DBUSER_PREFIX = 'DEV'
SOA_REPOS_DBPASSWORD = 'Welcome01'
BPM_ENABLED=true
BAM_ENABLED=true
B2B_ENABLED=true
ESS_ENABLED=true
def createBootPropertiesFile(directoryPath,fileName, username, password):
serverDir = File(directoryPath)
bool = serverDir.mkdirs()
fileNew=open(directoryPath + '/'+fileName, 'w')
fileNew.write('username=%s\n' % username)
fileNew.write('password=%s\n' % password)
fileNew.flush()
fileNew.close()
def createAdminStartupPropertiesFile(directoryPath, args):
adminserverDir = File(directoryPath)
bool = adminserverDir.mkdirs()
fileNew=open(directoryPath + '/startup.properties', 'w')
args=args.replace(':','\\:')
args=args.replace('=','\\=')
fileNew.write('Arguments=%s\n' % args)
fileNew.flush()
fileNew.close()
def changeDatasourceToXA(datasource):
print 'Change datasource '+datasource
cd('/')
cd('/JDBCSystemResource/'+datasource+'/JdbcResource/'+datasource+'/JDBCDriverParams/NO_NAME_0')
set('DriverName','oracle.jdbc.xa.client.OracleXADataSource')
set('UseXADataSourceInterface','True')
cd('/JDBCSystemResource/'+datasource+'/JdbcResource/'+datasource+'/JDBCDataSourceParams/NO_NAME_0')
set('GlobalTransactionsProtocol','TwoPhaseCommit')
cd('/')
def changeManagedServer(server,port,java_arguments):
cd('/Servers/'+server)
set('Machine' ,'LocalMachine')
set('ListenAddress',SERVER_ADDRESS)
set('ListenPort' ,port)
create(server,'ServerStart')
cd('ServerStart/'+server)
set('Arguments' , java_arguments+' -Dweblogic.Stdout='+LOG_FOLDER+server+'.out -Dweblogic.Stderr='+LOG_FOLDER+server+'_err.out')
set('JavaVendor','Sun')
set('JavaHome' , JAVA_HOME)
cd('/Server/'+server)
create(server,'SSL')
cd('SSL/'+server)
set('Enabled' , 'False')
set('HostNameVerificationIgnored', 'True')
if JSSE_ENABLED == true:
set('JSSEEnabled','True')
else:
set('JSSEEnabled','False')
cd('/Server/'+server)
create(server,'Log')
cd('/Server/'+server+'/Log/'+server)
set('FileName' , LOG_FOLDER+server+'.log')
set('FileCount' , 10)
set('FileMinSize' , 5000)
set('RotationType' ,'byTime')
set('FileTimeSpan' , 24)
print('Start...wls domain with template /opt/oracle/middleware12c/wlserver/common/templates/wls/wls.jar')
readTemplate('/opt/oracle/middleware12c/wlserver/common/templates/wls/wls.jar')
cd('/')
print('Set domain log')
create('base_domain','Log')
cd('/Log/base_domain')
set('FileName' ,LOG_FOLDER+DOMAIN+'.log')
set('FileCount' ,10)
set('FileMinSize' ,5000)
set('RotationType','byTime')
set('FileTimeSpan',24)
cd('/Servers/AdminServer')
# name of adminserver
set('Name',ADMIN_SERVER )
cd('/Servers/'+ADMIN_SERVER)
# address and port
set('ListenAddress',SERVER_ADDRESS)
set('ListenPort' ,7001)
setOption( "AppDir", APP_PATH )
create(ADMIN_SERVER,'ServerStart')
cd('ServerStart/'+ADMIN_SERVER)
set('Arguments' , ADM_JAVA_ARGUMENTS)
set('JavaVendor','Sun')
set('JavaHome' , JAVA_HOME)
cd('/Server/'+ADMIN_SERVER)
create(ADMIN_SERVER,'SSL')
cd('SSL/'+ADMIN_SERVER)
set('Enabled' , 'False')
set('HostNameVerificationIgnored', 'True')
if JSSE_ENABLED == true:
set('JSSEEnabled','True')
else:
set('JSSEEnabled','False')
cd('/Server/'+ADMIN_SERVER)
create(ADMIN_SERVER,'Log')
cd('/Server/'+ADMIN_SERVER+'/Log/'+ADMIN_SERVER)
set('FileName' ,LOG_FOLDER+ADMIN_SERVER+'.log')
set('FileCount' ,10)
set('FileMinSize' ,5000)
set('RotationType','byTime')
set('FileTimeSpan',24)
print('Set password...')
cd('/')
cd('Security/base_domain/User/weblogic')
# weblogic user name + password
set('Name',ADMIN_USER)
cmo.setPassword(ADMIN_PASSWORD)
if DEVELOPMENT_MODE == true:
setOption('ServerStartMode', 'dev')
else:
setOption('ServerStartMode', 'prod')
setOption('JavaHome', JAVA_HOME)
print('write domain...')
# write path + domain name
writeDomain(DOMAIN_PATH)
closeTemplate()
createAdminStartupPropertiesFile(DOMAIN_PATH+'/servers/'+ADMIN_SERVER+'/data/nodemanager',ADM_JAVA_ARGUMENTS)
createBootPropertiesFile(DOMAIN_PATH+'/servers/'+ADMIN_SERVER+'/security','boot.properties',ADMIN_USER,ADMIN_PASSWORD)
createBootPropertiesFile(DOMAIN_PATH+'/config/nodemanager','nm_password.properties',ADMIN_USER,ADMIN_PASSWORD)
es = encrypt(ADMIN_PASSWORD,DOMAIN_PATH)
readDomain(DOMAIN_PATH)
print('set domain password...')
cd('/SecurityConfiguration/'+DOMAIN)
set('CredentialEncrypted',es)
print('Set nodemanager password')
set('NodeManagerUsername' ,ADMIN_USER )
set('NodeManagerPasswordEncrypted',es )
cd('/')
setOption( "AppDir", APP_PATH )
print('Extend...osb domain with template /opt/oracle/middleware12c/osb/common/templates/wls/oracle.osb_template_12.1.3.jar')
addTemplate('/opt/oracle/middleware12c/oracle_common/common/templates/wls/oracle.wls-webservice-template_12.1.3.jar')
addTemplate('/opt/oracle/middleware12c/osb/common/templates/wls/oracle.osb_template_12.1.3.jar')
print 'Adding ApplCore Template'
addTemplate('/opt/oracle/middleware12c/oracle_common/common/templates/wls/oracle.applcore.model.stub.1.0.0_template.jar')
print 'Adding SOA Template'
addTemplate('/opt/oracle/middleware12c/soa/common/templates/wls/oracle.soa_template_12.1.3.jar')
if BAM_ENABLED == true:
print 'Adding BAM Template'
addTemplate('/opt/oracle/middleware12c/soa/common/templates/wls/oracle.bam.server_template_12.1.3.jar')
if BPM_ENABLED == true:
print 'Adding BPM Template'
addTemplate('/opt/oracle/middleware12c/soa/common/templates/wls/oracle.bpm_template_12.1.3.jar')
if WEBTIER_ENABLED == true:
print 'Adding OHS Template'
addTemplate('/opt/oracle/middleware12c/ohs/common/templates/wls/ohs_managed_template_12.1.3.jar')
if B2B_ENABLED == true:
print 'Adding B2B Template'
addTemplate('/opt/oracle/middleware12c/soa/common/templates/wls/oracle.soa.b2b_template_12.1.3.jar')
if ESS_ENABLED == true:
print 'Adding ESS Template'
addTemplate('/opt/oracle/middleware12c/oracle_common/common/templates/wls/oracle.ess.basic_template_12.1.3.jar')
addTemplate('/opt/oracle/middleware12c/em/common/templates/wls/oracle.em_ess_template_12.1.3.jar')
dumpStack()
print 'Change datasources'
print 'Change datasource LocalScvTblDataSource'
cd('/JDBCSystemResource/LocalSvcTblDataSource/JdbcResource/LocalSvcTblDataSource/JDBCDriverParams/NO_NAME_0')
set('URL',SOA_REPOS_DBURL)
set('PasswordEncrypted',SOA_REPOS_DBPASSWORD)
cd('Properties/NO_NAME_0/Property/user')
set('Value',SOA_REPOS_DBUSER_PREFIX+'_STB')
print 'Call getDatabaseDefaults which reads the service table'
getDatabaseDefaults()
changeDatasourceToXA('EDNDataSource')
changeDatasourceToXA('wlsbjmsrpDataSource')
changeDatasourceToXA('OraSDPMDataSource')
changeDatasourceToXA('SOADataSource')
if BAM_ENABLED == true:
changeDatasourceToXA('BamDataSource')
print 'end datasources'
print('Create machine LocalMachine with type UnixMachine')
cd('/')
create('LocalMachine','UnixMachine')
cd('UnixMachine/LocalMachine')
create('LocalMachine','NodeManager')
cd('NodeManager/LocalMachine')
set('ListenAddress',SERVER_ADDRESS)
print 'Change AdminServer'
cd('/Servers/'+ADMIN_SERVER)
set('Machine','LocalMachine')
print 'change soa_server1'
cd('/')
changeManagedServer('soa_server1',8001,SOA_JAVA_ARGUMENTS)
if BAM_ENABLED == true:
print 'change bam_server1'
cd('/')
changeManagedServer('bam_server1',9001,BAM_JAVA_ARGUMENTS)
print 'change osb_server1'
cd('/')
changeManagedServer('osb_server1',8011,OSB_JAVA_ARGUMENTS)
print 'Add server groups WSM-CACHE-SVR WSMPM-MAN-SVR JRF-MAN-SVR to AdminServer'
serverGroup = ["WSM-CACHE-SVR" , "WSMPM-MAN-SVR" , "JRF-MAN-SVR"]
setServerGroups(ADMIN_SERVER, serverGroup)
if ESS_ENABLED == true:
print 'Add server group SOA-MGD-SVRS,ESS-MGD-SVRS to soa_server1'
cd('/')
delete('ess_server1', 'Server')
serverGroup = ["SOA-MGD-SVRS","ESS-MGD-SVRS"]
else:
print 'Add server group SOA-MGD-SVRS to soa_server1'
serverGroup = ["SOA-MGD-SVRS"]
setServerGroups('soa_server1', serverGroup)
if BAM_ENABLED == true:
print 'Add server group BAM12-MGD-SVRS to bam_server1'
serverGroup = ["BAM12-MGD-SVRS"]
setServerGroups('bam_server1', serverGroup)
print 'Add server group OSB-MGD-SVRS-COMBINED to osb_server1'
serverGroup = ["OSB-MGD-SVRS-COMBINED"]
setServerGroups('osb_server1', serverGroup)
print 'end server groups'
updateDomain()
closeDomain();
createBootPropertiesFile(DOMAIN_PATH+'/servers/soa_server1/security','boot.properties',ADMIN_USER,ADMIN_PASSWORD)
if BAM_ENABLED == true:
createBootPropertiesFile(DOMAIN_PATH+'/servers/bam_server1/security','boot.properties',ADMIN_USER,ADMIN_PASSWORD)
createBootPropertiesFile(DOMAIN_PATH+'/servers/osb_server1/security','boot.properties',ADMIN_USER,ADMIN_PASSWORD)
print('Exiting...')
exit()
view raw soa.py hosted with ❤ by GitHub
With this as output.



When you want to create a cluster configuration you can use the following script.



WLHOME = '/opt/oracle/middleware12c/wlserver'
DOMAIN = 'soa_domain'
DOMAIN_PATH = '/opt/oracle/wlsdomains/domains/soa_domain'
APP_PATH = '/opt/oracle/wlsdomains/applications/soa_domain'
SERVER_ADDRESS = '10.10.10.21'
LOG_FOLDER = '/var/log/weblogic/'
JSSE_ENABLED = true
DEVELOPMENT_MODE = true
WEBTIER_ENABLED = false
ADMIN_SERVER = 'AdminServer'
ADMIN_USER = 'weblogic'
ADMIN_PASSWORD = 'weblogic1'
JAVA_HOME = '/usr/java/latest'
ADM_JAVA_ARGUMENTS = '-XX:PermSize=256m -XX:MaxPermSize=512m -Xms1024m -Xmx1532m -Dweblogic.Stdout='+LOG_FOLDER+'AdminServer.out -Dweblogic.Stderr='+LOG_FOLDER+'AdminServer_err.out'
OSB_JAVA_ARGUMENTS = '-XX:PermSize=256m -XX:MaxPermSize=512m -Xms1024m -Xmx1024m '
SOA_JAVA_ARGUMENTS = '-XX:PermSize=256m -XX:MaxPermSize=752m -Xms1024m -Xmx1532m '
BAM_JAVA_ARGUMENTS = '-XX:PermSize=256m -XX:MaxPermSize=512m -Xms1024m -Xmx1532m '
SOA_REPOS_DBURL = 'jdbc:oracle:thin:@soadb.example.com:1521/soarepos.example.com'
SOA_REPOS_DBUSER_PREFIX = 'DEV'
SOA_REPOS_DBPASSWORD = 'Welcome01'
BPM_ENABLED=true
BAM_ENABLED=true
B2B_ENABLED=true
ESS_ENABLED=true
def createBootPropertiesFile(directoryPath,fileName, username, password):
serverDir = File(directoryPath)
bool = serverDir.mkdirs()
fileNew=open(directoryPath + '/'+fileName, 'w')
fileNew.write('username=%s\n' % username)
fileNew.write('password=%s\n' % password)
fileNew.flush()
fileNew.close()
def createAdminStartupPropertiesFile(directoryPath, args):
adminserverDir = File(directoryPath)
bool = adminserverDir.mkdirs()
fileNew=open(directoryPath + '/startup.properties', 'w')
args=args.replace(':','\\:')
args=args.replace('=','\\=')
fileNew.write('Arguments=%s\n' % args)
fileNew.flush()
fileNew.close()
def changeDatasourceToXA(datasource):
print 'Change datasource '+datasource
cd('/')
cd('/JDBCSystemResource/'+datasource+'/JdbcResource/'+datasource+'/JDBCDriverParams/NO_NAME_0')
set('DriverName','oracle.jdbc.xa.client.OracleXADataSource')
set('UseXADataSourceInterface','True')
cd('/JDBCSystemResource/'+datasource+'/JdbcResource/'+datasource+'/JDBCDataSourceParams/NO_NAME_0')
set('GlobalTransactionsProtocol','TwoPhaseCommit')
cd('/')
def changeManagedServer(server,port,java_arguments):
cd('/Servers/'+server)
set('Machine' ,'LocalMachine')
set('ListenAddress',SERVER_ADDRESS)
set('ListenPort' ,port)
create(server,'ServerStart')
cd('ServerStart/'+server)
set('Arguments' , java_arguments+' -Dweblogic.Stdout='+LOG_FOLDER+server+'.out -Dweblogic.Stderr='+LOG_FOLDER+server+'_err.out')
set('JavaVendor','Sun')
set('JavaHome' , JAVA_HOME)
cd('/Server/'+server)
create(server,'SSL')
cd('SSL/'+server)
set('Enabled' , 'False')
set('HostNameVerificationIgnored', 'True')
if JSSE_ENABLED == true:
set('JSSEEnabled','True')
else:
set('JSSEEnabled','False')
cd('/Server/'+server)
create(server,'Log')
cd('/Server/'+server+'/Log/'+server)
set('FileName' , LOG_FOLDER+server+'.log')
set('FileCount' , 10)
set('FileMinSize' , 5000)
set('RotationType' ,'byTime')
set('FileTimeSpan' , 24)
print('Start...wls domain with template /opt/oracle/middleware12c/wlserver/common/templates/wls/wls.jar')
readTemplate('/opt/oracle/middleware12c/wlserver/common/templates/wls/wls.jar')
cd('/')
print('Set domain log')
create('base_domain','Log')
cd('/Log/base_domain')
set('FileName' ,LOG_FOLDER+DOMAIN+'.log')
set('FileCount' ,10)
set('FileMinSize' ,5000)
set('RotationType','byTime')
set('FileTimeSpan',24)
cd('/Servers/AdminServer')
# name of adminserver
set('Name',ADMIN_SERVER )
cd('/Servers/'+ADMIN_SERVER)
# address and port
set('ListenAddress',SERVER_ADDRESS)
set('ListenPort' ,7001)
setOption( "AppDir", APP_PATH )
create(ADMIN_SERVER,'ServerStart')
cd('ServerStart/'+ADMIN_SERVER)
set('Arguments' , ADM_JAVA_ARGUMENTS)
set('JavaVendor','Sun')
set('JavaHome' , JAVA_HOME)
cd('/Server/'+ADMIN_SERVER)
create(ADMIN_SERVER,'SSL')
cd('SSL/'+ADMIN_SERVER)
set('Enabled' , 'False')
set('HostNameVerificationIgnored', 'True')
if JSSE_ENABLED == true:
set('JSSEEnabled','True')
else:
set('JSSEEnabled','False')
cd('/Server/'+ADMIN_SERVER)
create(ADMIN_SERVER,'Log')
cd('/Server/'+ADMIN_SERVER+'/Log/'+ADMIN_SERVER)
set('FileName' ,LOG_FOLDER+ADMIN_SERVER+'.log')
set('FileCount' ,10)
set('FileMinSize' ,5000)
set('RotationType','byTime')
set('FileTimeSpan',24)
print('Set password...')
cd('/')
cd('Security/base_domain/User/weblogic')
# weblogic user name + password
set('Name',ADMIN_USER)
cmo.setPassword(ADMIN_PASSWORD)
if DEVELOPMENT_MODE == true:
setOption('ServerStartMode', 'dev')
else:
setOption('ServerStartMode', 'prod')
setOption('JavaHome', JAVA_HOME)
print('write domain...')
# write path + domain name
writeDomain(DOMAIN_PATH)
closeTemplate()
createAdminStartupPropertiesFile(DOMAIN_PATH+'/servers/'+ADMIN_SERVER+'/data/nodemanager',ADM_JAVA_ARGUMENTS)
createBootPropertiesFile(DOMAIN_PATH+'/servers/'+ADMIN_SERVER+'/security','boot.properties',ADMIN_USER,ADMIN_PASSWORD)
createBootPropertiesFile(DOMAIN_PATH+'/config/nodemanager','nm_password.properties',ADMIN_USER,ADMIN_PASSWORD)
es = encrypt(ADMIN_PASSWORD,DOMAIN_PATH)
readDomain(DOMAIN_PATH)
print('set domain password...')
cd('/SecurityConfiguration/'+DOMAIN)
set('CredentialEncrypted',es)
print('Set nodemanager password')
set('NodeManagerUsername' ,ADMIN_USER )
set('NodeManagerPasswordEncrypted',es )
cd('/')
setOption( "AppDir", APP_PATH )
print('Extend...osb domain with template /opt/oracle/middleware12c/osb/common/templates/wls/oracle.osb_template_12.1.3.jar')
addTemplate('/opt/oracle/middleware12c/oracle_common/common/templates/wls/oracle.wls-webservice-template_12.1.3.jar')
addTemplate('/opt/oracle/middleware12c/osb/common/templates/wls/oracle.osb_template_12.1.3.jar')
print 'Adding ApplCore Template'
addTemplate('/opt/oracle/middleware12c/oracle_common/common/templates/wls/oracle.applcore.model.stub.1.0.0_template.jar')
print 'Adding SOA Template'
addTemplate('/opt/oracle/middleware12c/soa/common/templates/wls/oracle.soa_template_12.1.3.jar')
if BAM_ENABLED == true:
print 'Adding BAM Template'
addTemplate('/opt/oracle/middleware12c/soa/common/templates/wls/oracle.bam.server_template_12.1.3.jar')
if BPM_ENABLED == true:
print 'Adding BPM Template'
addTemplate('/opt/oracle/middleware12c/soa/common/templates/wls/oracle.bpm_template_12.1.3.jar')
if WEBTIER_ENABLED == true:
print 'Adding OHS Template'
addTemplate('/opt/oracle/middleware12c/ohs/common/templates/wls/ohs_managed_template_12.1.3.jar')
if B2B_ENABLED == true:
print 'Adding B2B Template'
addTemplate('/opt/oracle/middleware12c/soa/common/templates/wls/oracle.soa.b2b_template_12.1.3.jar')
if ESS_ENABLED == true:
print 'Adding ESS Template'
addTemplate('/opt/oracle/middleware12c/oracle_common/common/templates/wls/oracle.ess.basic_template_12.1.3.jar')
addTemplate('/opt/oracle/middleware12c/em/common/templates/wls/oracle.em_ess_template_12.1.3.jar')
dumpStack()
print 'Change datasources'
print 'Change datasource LocalScvTblDataSource'
cd('/JDBCSystemResource/LocalSvcTblDataSource/JdbcResource/LocalSvcTblDataSource/JDBCDriverParams/NO_NAME_0')
set('URL',SOA_REPOS_DBURL)
set('PasswordEncrypted',SOA_REPOS_DBPASSWORD)
cd('Properties/NO_NAME_0/Property/user')
set('Value',SOA_REPOS_DBUSER_PREFIX+'_STB')
print 'Call getDatabaseDefaults which reads the service table'
getDatabaseDefaults()
changeDatasourceToXA('EDNDataSource')
changeDatasourceToXA('wlsbjmsrpDataSource')
changeDatasourceToXA('OraSDPMDataSource')
changeDatasourceToXA('SOADataSource')
if BAM_ENABLED == true:
changeDatasourceToXA('BamDataSource')
print 'end datasources'
setOption( "AppDir", APP_PATH )
print('Create machine LocalMachine with type UnixMachine')
cd('/')
create('LocalMachine','UnixMachine')
cd('UnixMachine/LocalMachine')
create('LocalMachine','NodeManager')
cd('NodeManager/LocalMachine')
set('ListenAddress',SERVER_ADDRESS)
print 'Change AdminServer'
cd('/Servers/'+ADMIN_SERVER)
set('Machine','LocalMachine')
cd('/')
if ESS_ENABLED == true:
delete('ess_server1', 'Server')
if BAM_ENABLED == true:
delete('bam_server1', 'Server')
delete('soa_server1', 'Server')
delete('osb_server1', 'Server')
print 'Create SoaCluster'
cd('/')
create('SoaCluster', 'Cluster')
print 'Create SoaServer1'
cd('/')
create('SoaServer1', 'Server')
changeManagedServer('SoaServer1',8001,SOA_JAVA_ARGUMENTS)
print 'Create SoaServer2'
cd('/')
create('SoaServer2', 'Server')
changeManagedServer('SoaServer2',8002,SOA_JAVA_ARGUMENTS)
cd('/')
assign('Server','SoaServer1','Cluster','SoaCluster')
assign('Server','SoaServer2','Cluster','SoaCluster')
if BAM_ENABLED == true:
print 'Create BamCluster'
cd('/')
create('BamCluster', 'Cluster')
print 'Create BamServer1'
cd('/')
create('BamServer1', 'Server')
changeManagedServer('BamServer1',9001,BAM_JAVA_ARGUMENTS)
print 'Create BamServer2'
cd('/')
create('BamServer2', 'Server')
changeManagedServer('BamServer2',9002,BAM_JAVA_ARGUMENTS)
cd('/')
assign('Server','BamServer1','Cluster','BamCluster')
assign('Server','BamServer2','Cluster','BamCluster')
print 'Create OsbCluster'
cd('/')
create('OsbCluster', 'Cluster')
print 'Create OsbServer1'
cd('/')
create('OsbServer1', 'Server')
changeManagedServer('OsbServer1',8011,OSB_JAVA_ARGUMENTS)
print 'Create OsbServer2'
cd('/')
create('OsbServer2', 'Server')
changeManagedServer('OsbServer2',8012,OSB_JAVA_ARGUMENTS)
cd('/')
assign('Server','OsbServer1','Cluster','OsbCluster')
assign('Server','OsbServer2','Cluster','OsbCluster')
print 'Add server groups WSM-CACHE-SVR WSMPM-MAN-SVR JRF-MAN-SVR to AdminServer'
serverGroup = ["WSM-CACHE-SVR" , "WSMPM-MAN-SVR" , "JRF-MAN-SVR"]
setServerGroups(ADMIN_SERVER, serverGroup)
if ESS_ENABLED == true:
print 'Add server group SOA-MGD-SVRS,ESS-MGD-SVRS to soa_server1'
cd('/')
serverGroup = ["SOA-MGD-SVRS","ESS-MGD-SVRS"]
else:
print 'Add server group SOA-MGD-SVRS to SoaServer1 2'
serverGroup = ["SOA-MGD-SVRS"]
setServerGroups('SoaServer1', serverGroup)
setServerGroups('SoaServer2', serverGroup)
if BAM_ENABLED == true:
print 'Add server group BAM12-MGD-SVRS to BamServer1 2'
serverGroup = ["BAM12-MGD-SVRS"]
setServerGroups('BamServer1', serverGroup)
setServerGroups('BamServer2', serverGroup)
print 'Add server group OSB-MGD-SVRS-COMBINED to OsbServer1 2'
serverGroup = ["OSB-MGD-SVRS-COMBINED"]
setServerGroups('OsbServer1', serverGroup)
setServerGroups('OsbServer2', serverGroup)
print 'end server groups'
updateDomain()
closeDomain();
createBootPropertiesFile(DOMAIN_PATH+'/servers/SoaServer1/security','boot.properties',ADMIN_USER,ADMIN_PASSWORD)
createBootPropertiesFile(DOMAIN_PATH+'/servers/SoaServer2/security','boot.properties',ADMIN_USER,ADMIN_PASSWORD)
if BAM_ENABLED == true:
createBootPropertiesFile(DOMAIN_PATH+'/servers/BamServer1/security','boot.properties',ADMIN_USER,ADMIN_PASSWORD)
createBootPropertiesFile(DOMAIN_PATH+'/servers/BamServer2/security','boot.properties',ADMIN_USER,ADMIN_PASSWORD)
createBootPropertiesFile(DOMAIN_PATH+'/servers/OsbServer1/security','boot.properties',ADMIN_USER,ADMIN_PASSWORD)
createBootPropertiesFile(DOMAIN_PATH+'/servers/OsbServer2/security','boot.properties',ADMIN_USER,ADMIN_PASSWORD)
print('Exiting...')
exit()
view raw cluster.py hosted with ❤ by GitHub

Thursday, July 31, 2014

Test your Application with the WebLogic Maven plugin

In this blogpost I will show you how easy it is to add some unit tests to your application when you use Maven together with the 12.1.3 Oracle software ( like WebLogic , JDeveloper or Eclipse OEPE).

To demonstrate this, I will create a RESTful Person Service in JDeveloper 12.1.3 which will use the Maven project layout.

We will do the following:

Create a Project and Application based on a Maven Archetype.
Create a JAX-RS 2.0 Person Resource

In the Maven Test phase, we will test this Person Rest Service.
  • Use JerseyTest to test the Person Resource
  • Use JerseyTest and Mockito to test and mock the Person Rest Service.

In the Maven Integration Test phase, we will test the Person Resource on a WebLogic domain and run some external soupUI tests.

  • Create a WebLogic Domain
  • Start the AdminServer
  • Deploy the JAX-RS 2.0 shared library and our Person Rest Service
  • Run some soapUI test cases.
  • Remove the WebLogic domain.

Before we can start, we need to use oracle-maven-sync-12.1.3.jar plugin to populate our local or maven repository with all the Oracle binaries.

For more information how to do this you can take a look at one of the following links.


We start by creating a new application in JDeveloper 12.1.3


Go to the Maven tree and select Generate from Archetype.



 Provide the maven Group and Artifact id and lookup the basic-webservice Archetype.


When you search for webLogic you will find the basic web service archetypes. Make sure you select the 12.1.3 one.


This will create a Web Service Project but we also need to create an application. So the next step is the Application creation dialog.


Because we want to use JAX-RS and not JAX-WS, so we need to delete the SayHello web service.



Next step is adding the REST Web Service feature to this project. 


Create a RESTful Service class



Choose JAX-RS 2.0 Style


Choose RESTful Service From New


 Provide all the REST service details and enable application/json as Media Types.


And viola we got our Person RESTful Service.


JDeveloper will automatically add the JAX-RS 2.0 shared library to your project.



This finishes our basic service.

This is how the final Person service will look like.

package com.example.rest.services;
import com.example.rest.data.PersonDao;
import com.example.rest.data.PersonNotFoundException;
import com.example.rest.entities.Person;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
@Path("person")
@Consumes("application/json")
@Produces("application/json")
public class PersonResource {
public PersonResource() {
}
PersonDao personDao = new PersonDao();
public void setPersonDao(PersonDao personDao) {
this.personDao = personDao;
}
@GET
public Response getPersons() {
List<Person> persons = personDao.findAll();
return Response.ok(persons.toArray(new Person[persons.size()])).build();
}
@GET
@Path("/{id}")
public Response getPerson(@PathParam("id") Integer id) {
try {
Person person = personDao.findPerson(id);
return Response.ok(person).build();
} catch (PersonNotFoundException e) {
return Response.status(Response.Status.NOT_FOUND).build();
}
}
}
We can now add some unit tests to the Maven Test phase. We will make 2 JUnit test cases where we will use JerseyTest, so we can test the Person Resource and one with Mockito so we can also mock the data of the Person Resource.

For these tests a lightweight grizzly2 HTTP container will be started by Maven.

The pom's dependency libraries which we will need.

<dependencies>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-grizzly2</artifactId>
<version>2.11</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework</groupId>
<artifactId>jersey-test-framework-core</artifactId>
<version>2.11</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.bundles.repackaged</groupId>
<artifactId>jersey-guava</artifactId>
<version>2.11</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-servlet</artifactId>
<version>2.11</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.11</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.11</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.11</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
</dependencies>
view raw pom.xml hosted with ❤ by GitHub
Using only JerseyTest is probably not so meaningful because you probably also need an emulate your EJB's but here you have the JerseyTest snippet

package test.com.example.rest.services;
import com.example.rest.entities.Person;
import com.example.rest.services.PersonResource;
import java.util.List;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import org.junit.Test;
public class PersonResourceTest extends JerseyTest {
public PersonResourceTest() {
}
@Override
protected Application configure(){
return new ResourceConfig(PersonResource.class);
}
@Test
public void findAll() {
final Response result = target("person").request()
.accept(MediaType.APPLICATION_JSON)
.get(Response.class);
if(result.getStatus() != Response.Status.OK.getStatusCode()){
fail("Wrong status code "+result.getStatus());
}
List<Person> persons = result.readEntity(new GenericType<List<Person>>(){});
assertEquals(2,persons.size());
for ( Person person : persons) {
assertNotNull(person.getId());
if ( person.getId() == 1 ) {
assertEquals("Edwin",person.getFirstName());
}
if ( person.getId() == 2 ) {
assertEquals("Mark",person.getFirstName());
}
}
}
@Test
public void findPerson() {
final Response result = target("person/1").request()
.accept(MediaType.APPLICATION_JSON)
.get(Response.class);
if(result.getStatus() != Response.Status.OK.getStatusCode()){
fail("Wrong status code "+result.getStatus());
}
Person person = result.readEntity(new GenericType<Person>(){});
assertEquals("Edwin",person.getFirstName());
}
@Test
public void findPersonNotfound() {
final Response result = target("person/100").request()
.accept(MediaType.APPLICATION_JSON)
.get(Response.class);
assertEquals(result.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
}
}
And the JerseyTest with Mockito snippet.

package test.com.example.rest.services;
import com.example.rest.data.PersonDao;
import com.example.rest.data.PersonNotFoundException;
import com.example.rest.entities.Person;
import com.example.rest.services.PersonResource;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.mockito.runners.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class PersonResourceMockTest extends JerseyTest {
public PersonResourceMockTest() {
}
private PersonDao personDao;
@Override
protected Application configure(){
PersonResource personResource = new PersonResource();
personDao = mock(PersonDao.class);
personResource.setPersonDao(personDao);
return new ResourceConfig().registerInstances(personResource);
}
@Test
public void findAll() {
List<Person> mockPersons = new ArrayList<Person>();
mockPersons.add(new Person(1,"John","Doe"));
when(personDao.findAll()).thenReturn(mockPersons);
Response result = target("person").request()
.accept(MediaType.APPLICATION_JSON)
.get(Response.class);
if(result.getStatus() != Response.Status.OK.getStatusCode()){
fail("Wrong status code "+result.getStatus());
}
verify(personDao).findAll();
List<Person> persons = result.readEntity(new GenericType<List<Person>>(){});
assertEquals(1,persons.size());
for ( Person person : persons) {
assertNotNull(person.getId());
if ( person.getId() == 1 ) {
assertEquals("John",person.getFirstName());
}
}
}
@Test
public void findPerson() throws PersonNotFoundException {
Integer id = 10;
Person mockPerson = new Person(id,"John","Doe");
when(personDao.findPerson(id)).thenReturn(mockPerson);
final Response result = target("person/"+id).request()
.accept(MediaType.APPLICATION_JSON)
.get(Response.class);
verify(personDao).findPerson(id);
if(result.getStatus() != Response.Status.OK.getStatusCode()){
fail("Wrong status code "+result.getStatus());
}
Person person = result.readEntity(new GenericType<Person>(){});
assertEquals("John",person.getFirstName());
}
}


We can now run mvn clean test


This is nice, but the next question is "Can we also run this Application on a WebLogic Container and do some external tests"

For this we can use the weblogic-maven-plugin in the integration-test Maven phase.
The WebLogic plugin can create a new WebLogic Domain, Start the AdminServer, Deploy the JAX-RS 2 shared library, our Application and off course stop the AdminServer and remove the domain.

<properties>
<project_mdwhome>/Users/edwin/Oracle/JDevMiddleware12.1.3_normal</project_mdwhome>
<project_adminurl>t3://127.0.0.1:7001</project_adminurl>
<project_wlsusername>weblogic</project_wlsusername>
<project_wlspassword>weblogic1</project_wlspassword>
<project_wstarget>AdminServer</project_wstarget>
<project_wsurl>http://127.0.0.1:7001</project_wsurl>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.oracle.weblogic</groupId>
<artifactId>weblogic-maven-plugin</artifactId>
<version>12.1.3-0-0</version>
<configuration>
<middlewareHome>${project_mdwhome}</middlewareHome>
<user>${project_wlsusername}</user>
<password>${project_wlspassword}</password>
<domainHome>${project.build.directory}/base_domain</domainHome>
<adminurl>${project_adminurl}</adminurl>
<targets>${project_wstarget}</targets>
</configuration>
<executions>
<execution>
<id>wls-create-domain</id>
<phase>pre-integration-test</phase>
<goals>
<goal>create-domain</goal>
</goals>
<configuration>
<failOnDomainExists>true</failOnDomainExists>
</configuration>
</execution>
<execution>
<id>wls-start-domain</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start-server</goal>
</goals>
</execution>
<execution>
<id>wls-deploy-jax-rs</id>
<phase>pre-integration-test</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<source>${project_mdwhome}/wlserver/common/deployable-libraries/jax-rs-2.0.war</source>
<verbose>true</verbose>
<name>jax-rs</name>
<library>true</library>
</configuration>
</execution>
<execution>
<id>wls-deploy</id>
<phase>pre-integration-test</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>
<verbose>true</verbose>
<name>${project.build.finalName}</name>
</configuration>
</execution>
<execution>
<id>wls-undeploy</id>
<phase>post-integration-test</phase>
<goals>
<goal>undeploy</goal>
</goals>
<configuration>
<verbose>true</verbose>
<name>${project.build.finalName}</name>
</configuration>
</execution>
<execution>
<id>wls-stop-domain</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop-server</goal>
</goals>
</execution>
<execution>
<id>wls-destroy-domain</id>
<phase>post-integration-test</phase>
<goals>
<goal>remove-domain</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
view raw pom2.xml hosted with ❤ by GitHub
In SoapUI 5.0 I made a Testcase for this Person REST Service and add the soapUI project xml to our JDeveloper project.


The Maven soapUI plugin , In my case I added the smartbear private repository to my own Nexus repository.

<plugin>
<groupId>com.smartbear.soapui</groupId>
<artifactId>soapui-maven-plugin</artifactId>
<version>5.0.0</version>
<configuration>
<projectFile>${project.basedir}/src/main/test/resources/soapui/person-soapui-project.xml</projectFile>
<junitReport>true</junitReport>
<printReport>true</printReport>
<exportAll>true</exportAll>
<testSuite>PersonTestSuite1</testSuite>
<testCase>Persons</testCase>
<endpoint>${project_wsurl}</endpoint>
<outputFolder>${project.build.directory}/soapui</outputFolder>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
view raw soapui.xml hosted with ❤ by GitHub
Now we can start maven with mvn clean deploy

Create a new WebLogic domain ( inside the maven target folder ),  deploy our application together with the shared library.


Start the soapUI testcases.
 

With this as result.


That's all.

You can find this demo project on github https://github.com/biemond/Person-Rest-MavenApp