Skip to content
/ easyrs Public

This library provides an easy way to test the basic CRUD operation for your endpoints. The tests can be executed within Arquillian or as a Singleton application

License

Notifications You must be signed in to change notification settings

nirodg/easyrs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

easyrs

Join the chat at https://gitter.im/nirodg/easyrsBuild StatusCodacy Badge

What would you say if would be a way how to reduce the time writing comparison tests for your endpoints.. or what if you could test it as a Singleton or within Arquillian?

Generating basic crud operations it´s so fast that within 5 minutes you have them already generated ( al right, might take you 2 minutes longer the first time 😉 )

So let´s define our test as it´s shown below:

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

Define a JSON file for your entity where the keys represent the Entity's field :

{
	"create": {
		"guid": "",
		"name": "",
		"email": ""
	},
	"update": {
		"guid": "",
		"name": "",
		"email": ""
	},
	"getAll": 0
}

and voilà, tests generated!

public class UserRestTestEndpoint extends Container<UserDTO,UserEndpoint> {

  // Here you can define your global variables

  @Before
  public void setUp() {
    // Here you can initialize your variables

  }

  @Test
  public void getAll() {
    List<UserDTO> entities = (ArrayList<UserDTO>) getData(GET_ALL);
    List<UserDTO> fetchedEntities = (ArrayList<UserDTO>) getClient().getAll();

    Assert.assertEquals(entities.size(), fetchedEntities.size());
  }

  @Test
  public void create() {
    UserDTO entity = (UserDTO) getData(PUT);
    Assert.assertNotNull(entity);

    UserDTO fetchedEntity = (UserDTO) getClient().put(entity);
    Assert.assertNotNull(fetchedEntity);

    Assert.assertEquals(entity, fetchedEntity);
  }

  @Test
  public void update() {
    UserDTO entity = (UserDTO) getData(POST);
    Assert.assertNotNull(entity);

    entity = (UserDTO) getClient().put(entity);
    Assert.assertNotNull(entity);

    UserDTO fetchedEntity = (UserDTO) getClient().post(entity.getGuid(), entity);
    Assert.assertNotNull(fetchedEntity);

    Assert.assertEquals(entity, fetchedEntity);
  }

  @Test
  public void delete() {
    UserDTO entity = (UserDTO) getData(DELETE);
    Assert.assertNotNull(entity);

    entity = (UserDTO) getClient().put(entity);
    Assert.assertNotNull(entity);

    Object fetchedEntity = getClient().delete(entity.getGuid());
    if (fetchedEntity instanceof UserDTO) {
        	Assert.assertNull(fetchedEntity);
        
	} else if (fetchedEntity.getClass().equals(boolean.class)
        	|| fetchedEntity.getClass().equals(Boolean.class)) { 
        Assert.assertTrue((boolean) fetchedEntity);
	};
  }
  

Still interested 😄? Then please take a moment to check how to setup properly EasyRs withit your project.

Currently you can checkout easyrs-example where you can find a simple war project runing within EasyRs

Contribute

In case you would like to contribute updating the documentation, improving the functionalities, reporting issues or fixing them please, you`re more than welcome 😄 . However, please have a look to the already defined contribute's guide

License

MIT © Dorin Brage

About

This library provides an easy way to test the basic CRUD operation for your endpoints. The tests can be executed within Arquillian or as a Singleton application

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages