Search This Blog

Chandima Janakantha's Dev Blog

Wednesday, November 28, 2018

ReadyApi SoapApi Cheats and Notes


To Add an Step right click on the Test case and choose the script type.

To see any values log the value

def val = "fffff";
log.info(val);

Use Groovy script to do any tasks which are not already available.

to create a new property at test case level
def newProperty = 'Test' + System.currentTimeMillis();
testRunner.testCase.setPropertyValue("newProperty", newProperty);

And then it can be used in a subsequent step with
def property1 =  context.expand( '${#TestCase#newProperty}')


Reading xml request and response for soap steps

after the step can use following groovy script step to save the request and response to testcase level properties

//first grab the request, response , row request, row response.
def request  = testRunner.testCase.getTestStepByName("stepName").getProperty("Request").getValue();
def response  = testRunner.testCase.getTestStepByName("stepName").getProperty("Response").getValue();

def rawRequest  = testRunner.testCase.getTestStepByName("stepName").getProperty("RawRequest").getValue();
def rawResponse  = testRunner.testCase.getTestStepByName("stepName").getProperty("RawResponse").getValue();

//then save them to testcase level properties.

testRunner.testCase.setPropertyValue("xmlRequest", request);
testRunner.testCase.setPropertyValue("xmlResponse", response);

testRunner.testCase.setPropertyValue("rawRequest", rawRequest);
testRunner.testCase.setPropertyValue("rawResponse", rawResponse);


To query database
create a database step and select appropriate driver and connection string. place the drive in the SoapUI jars folder.

write a SQL select query and execute and see the results in the response pane.

to grab the results for assertions add an script assertion
click on the database script step, click on Assertions tab, click on + and select Script Assertion
right click and select Get Data > pick the step or test case to get the data from, eg the database step and then pick a variable.

let's say we picked ResponseAsXml
then click on Add button, pick the element from the xml view.(xpath expression is displayed when the element is selected). click OK. give a name for the property. click OK. this will add a linie to the script. something like below.

def responseAsXml = context.expand( '${MyStepName#ResponseAsXml#//Results[1]/ResultSet[1]/Row[1]/COMMUNICATION_ID[1]}' )


Sunday, November 25, 2018

Spring boot configuration to run both in websphere and tomcat with jta


if required to decalare additional configuration from dependancy jar modules use component scan
@SpringBootApplication(scanBasePackages = {"au.com.myserver.app.*", "au.com.otherApp.service.*"})

if required to exclude all datasource autoconfiguration
@SpringBootApplication(scanBasePackages = {"aa.bb.cc.*", "aa.bb.cd.ee.*"}, exclude = {DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
//or can specify on application.properties or application.yaml
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration

creating Tomcat JNDI datasources

@Configuration@Profile({ "tomcat" })
public class TomcatWebConfiguration  {


    @Value("${spring.datasource.app.jdbc-url}")
    private String appDataSourceUrl;
    @Value("${spring.datasource.app.username}")
    private String appDataSourceUsername;
    @Value("${spring.datasource.app.password}")
    private String appDataSourcePassword;
    @Value("${spring.datasource.app.jndi-name}")
    private String appDataSourceJndi;

    @Bean    public TomcatServletWebServerFactory tomcatFactory() {
        return new TomcatServletWebServerFactory() {
            @Override  protected TomcatWebServer getTomcatWebServer(org.apache.catalina.startup.Tomcat tomcat) {
                tomcat.enableNaming();                
                return super.getTomcatWebServer(tomcat);
            }

            @Override  protected void postProcessContext(Context context) {

                // context                
                ContextResource resource = new ContextResource();
                resource.setName(appDataSourceJndi);                
                resource.setType(DataSource.class.getName());
                resource.setProperty("url", appDataSourceUrl);
                resource.setProperty("username", appDataSourceUsername);
                resource.setProperty("password", appDataSourcePassword);
                context.getNamingResources()
                        .addResource(resource);
            }

        };    
    }

}





for SprintBootTest use following to disable autoconfigure
@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT, properties = {"spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration"})



Mockito notes


to use @Mock and @MockInjects do either of these


@RunWith(MockitoJUnitRunner.class)
public class MockitoAnnotationTest {
    ...
}

@Before
public void init() {
    MockitoAnnotations.initMocks(this);
}


Thursday, November 15, 2018

Useful Online tools

Json Path Online Evaluator
http://jsonpath.com/?

One stop shop for lot of online tools
https://www.regextester.com/

big number converter
https://www.mobilefish.com/services/big_number/big_number.php

Monday, November 12, 2018

iBM HTTP SERVER VIRTUAL HOST CONFIG FOR PROXY

<VirtualHost *:443>
 DocumentRoot "d:/IBM/HTTPServer/htdocs"
 ServerName localtest.com.au
 ServerAlias localtest
 ErrorLog logs/localtest-error.log
 CustomLog logs/localtest-access.log deflatelog
 Options -FollowSymLinks -Indexes -ExecCGI
 SSLEnable
 SSLProtocolDisable SSLv3 SSLv2
    SSLClientAuth Required
    SSLClientAuthRequire (CN = "www.myserver.com.au" || CN = "fake server" || OU="LTX,ABC")

## SSLv3 128 bit Ciphers
 #SSLCipherSpec SSL_RSA_WITH_RC4_128_MD5
 #SSLCipherSpec SSL_RSA_WITH_RC4_128_SHA
## FIPS approved SSLV3 and TLSv1 128 bit AES Cipher
 SSLCipherSpec TLS_RSA_WITH_AES_128_CBC_SHA
## FIPS approved SSLV3 and TLSv1 256 bit AES Cipher
 SSLCipherSpec TLS_RSA_WITH_AES_256_CBC_SHA
## Triple DES 168 bit Ciphers
 ## These can still be used, but only if the client does
 ## not support any of the ciphers listed above.
 #Commented out - birthday attack
 #SSLCipherSpec SSL_RSA_WITH_3DES_EDE_CBC_SHA
SSLServerCert mysever.com.au
    ProxyPass     /angular     http://localhost:4200/angular
    ProxyPass     /website1   http://localhost:8081/website
</VirtualHost>

Wednesday, February 24, 2010

Spring Circular Dependancies

Though it's not always normal to have Circular referencing service beans to be configured in spring, it's not a sin to do so. There are cases where each action is handled by a particular service and for that the call much travel between beans and bean methods to accomplish that. But in most cases this can be handled more elegantly by carefully re-organising the sequence of the calls.

When this is not possible, it requires to have circular dependency in spring beans.
But if you have Bean A and Bean B and if A has a reference to B and B has a reference to B, spring when initializing will throw error. There are few ways to get around this situation.

1. Implement ApplicationContextAware in one of the beans (let's say Bean A) and when the call to Bean B is first done from Bean A, look for Bean B in application context and initialize. This will be only required to be done for the first call, since after that in a singleton the reference of Bean B is catched. Therefore in the spring configuration only B will depend on A. A won't depend on B. But in real code A will depend on B and it will be referenced when it's first used.

2. Define A's dependency on B in the spring context, but while setting B on A set the reverse relation ship also.


in Bean A
setB(Bean b)
{
this.b = b;
b.setA(this);
}

in Bean B
set A(Bean a)
{
this.a = a;
}

in spring configuration only setB() is configured as setter injection. So B will be created first, but when setting B on A, A on B also is set.

Thursday, February 11, 2010

Hibernate / Dao/ Object Graphs

Hibernate is an excellent ORM package. It eliminates all SQL/ data access code from a java project. But it introduces a problem if not care is taken in designing.

In one of my projects, we modeled a very deep tree of objects and if required with one single query we could load the entire database. This is dangerous and has big performance hits.

The approach for the next project would be.
1. Use Hibernate and keep data integrity with constrains.
2. Have a DAO to control every 3 or 4 model objects. each dao will manage a coarse grained object.
3. Hibernate cannot fetch a deep tree object because the objects will be disconnected at hibernate level.
4. for querying 'private fields' will be used. in the hibernate hbm.xml files the relationships for queries will be done using 'field' accessor. That means still querying is possible, but no deep fetching or lazy initializing exceptions which can happen due to getters in closed session.