Skip to content

Latest commit

 

History

History
183 lines (142 loc) · 6.18 KB

installation.md

File metadata and controls

183 lines (142 loc) · 6.18 KB

Installing

In order to have it running you should have your POM file as followed

<properties>
    <version.easyrs>0.0.2-SNAPSHOT</version.easyrs>
</properties>

<dependencies>

    <!-- -->
    <dependency>
        <groupId>com.dorinbrage</groupId>
        <artifactId>easyrs</artifactId>
        <version>${version.easyrs}</version>
    </dependency>
    <!-- -->

</dependencies>

<profiles>
        <profile>
            <id>easyrs-generate-tests</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.5.1</version>
                        <configuration>
                            <source>1.8</source>
                            <target>1.8</target>
                            <annotationProcessors>
                                <annotationProcessor>com.dorinbrage.easyrs.processor.EndpointProcessor</annotationProcessor>
                            </annotationProcessors>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

Defining your endpoint test

  1. Create an inteface under src/test/java. Example: UserRest

  2. Add the annotation @EndpointTest. The options are the followed:

Attribute Description
endpoint Reference to your endpoint class. Required
entity Reference to your entity class. It can be a simple POJO class or DAO. Required
operations The options are GET_ALL, PUT, POST and DELETE. By default will generate all the methods. Example: operations = {ClientOperation.GET, ClientOperation.DELETE} Optional
execution Either generated the class for being deployable withinARQUILLIAN or as a SINGLETON. By default is ExecutionMode.SINGLETON Optional
identifier Reference to the ID's field. The options are ID, GUID and UUID. By default is UUIDIdentifier.GUID Optional
  1. Execute mvn install -Peasyrs-generate-tests

  2. The generated classes will be under /target/generated-test-sources/test-annotations

  3. Optional - Right click on that folder and Use as Source Folder

  4. Under src\test\resources create the same structure as the endpoint has and under this structure a json file must be defined with the same name as the interface. Example: src\test\resources\com\example\easyrs\UserRest.json . For autogenerated JSON files check how to Autogenerate JSONs

{ 	
	// DO NOT CHANGE THE KEYS
	
	"getAll" : 0, // Total result
	"create" : "", // Entity to be created
	"update" : "", // Entity to be updated
	
}

At the end it should look like:

package com.example.easyrs;

import com.dorinbrage.easyrs.processor.annotation.EndpointTest;
import com.dorinbrage.github.jme.user.dto.UserDto;

@EndpointTest(entity=UserDto.class, endpoint=UserEndpoint.class)
public interface UserRest {

}

The JSON file should look like. Important, do not use other keys

{
	"getAll" : 2, // Total result
	   "create" : {
        "user" : "Admin",
        "enabled" : true
    },
    "update" : {
        "user" : "Moderator",
        "enabled" : false
    }
}

Autogenerated JSONs

Because I wanted to make it easier for you now you have the chance to have the JSONs generated automatically and you only concern would be to fill in the values

  • Add the two properties to your pom file - They are just arguments for the compiler
<properties>
    .... 

    <arg.resource.folder>-AresourceFolder=${project.basedir}/src/main/resources</arg.resource.folder>
    <arg.test.resource.folder>-AresourceFolder=${project.basedir}/src/test/resources</arg.test.resource.folder>
    <arg.default.resource.folder>-AresourceFolder=${project.build.directory}</arg.default.resource.folder>

    .... 
</properties>
  • Add the new profile and use the proper argument base on your needs
<profile>
    <id>easyrs-generate-json</id>
    <activation>
        <activeByDefault>false</activeByDefault>
    </activation>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <annotationProcessors>
                        <annotationProcessor>com.dorinbrage.easyrs.processor.JsonProcessor</annotationProcessor>
                    </annotationProcessors>
                    <compilerArgs>
                        <compilerArg>${arg.resource.folder}</compilerArg>
                    </compilerArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>
</profile>

The arguments are the followed:

Property Description
${arg.resource.folder} The JSON files will be created under <your_project>/src/main/resources
${arg.test.resource.folder} The JSON files will be created under <your_project>/src/test/resources
${arg.default.resource.folder} The JSON files will be created under <your_project>/target

Note: If your DTO is under /src/main/resources then you should use ${arg.resource.folder} due the JSON will be fetched based on where the DTO is created, either /src/main/java or /src/test/java

Rest Client - Authentication

Authentication mecanisms which are supported:

  1. Basic HTTP Authentication
Property Description
client.host By default the host will appoint to http://localhost Optional
client.user It can be either the username or email's account. Depends of how you authenticate against the REST Endpoint Optional
client.pass The password Optional

License

MIT © Dorin Brage