Skip to content

Commit

Permalink
[refs #1] - Add path test added
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjoy-sust committed Jan 21, 2018
1 parent 879251b commit fad7a9b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/test/java/com/fm/assignment/repository/PathRepositoryTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package com.fm.assignment.repository;

import com.fm.assignment.core.dao.PathRepository;
import com.fm.assignment.core.dao.PlaceRepository;
import com.fm.assignment.core.entity.PathEntity;
import com.fm.assignment.core.entity.PlaceEntity;
import com.fm.assignment.core.enums.TransportTypeEnum;
import com.fm.assignment.repository.constants.PathEntityConstants;
import com.fm.assignment.repository.constants.PlaceEntityConstants;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -20,10 +26,46 @@ public class PathRepositoryTest {
@Autowired
PathRepository pathRepository;

@Autowired
PlaceRepository placeRepository;

@Test
public void addTest()
{
List<PlaceEntity> placeEntities = savePlaceData(2);

PathEntity pathEntity = new PathEntity();
pathEntity.setFromCode(placeEntities.get(0));
pathEntity.setToCode(placeEntities.get(1));
pathEntity.setContainerSize(PathEntityConstants.CONTAINER_SIZE);
pathEntity.setCost(PathEntityConstants.COST);
pathEntity.setDuration(PathEntityConstants.DURATION);
pathEntity.setRouteType(TransportTypeEnum.Road);
PathEntity savedPath = pathRepository.save(pathEntity);
Assert.assertNotNull(savedPath);
pathRepository.delete(savedPath);
Assert.assertNull(pathRepository.findOne(savedPath.getId()));
placeRepository.delete(placeEntities);
}

@Test
public void findPathByContainerSize()
{
List<PathEntity> byContainerSize = pathRepository.findByContainerSize(20);
Assert.assertNotNull(byContainerSize);
}

private List<PlaceEntity> savePlaceData(int noOfPlaces) {
List<PlaceEntity> savedPlaces = new ArrayList<>();
for (int i=1;i<=noOfPlaces;i++) {
PlaceEntity pe = new PlaceEntity();
pe.setName(PlaceEntityConstants.PLACE_NAME.concat(String.valueOf(i)));
pe.setCode(PlaceEntityConstants.PLACE_CODE.concat(String.valueOf(i)));
pe.setLatitude(PlaceEntityConstants.PLACE_LATITUDE+i);
pe.setLongitude(PlaceEntityConstants.PLACE_LONGITUDE+i);
pe = placeRepository.save(pe);
savedPlaces.add(pe);
}
return savedPlaces;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.fm.assignment.repository.constants;

/**
* Created by Lenovo on 22/01/2018.
*/
public class PathEntityConstants {
public static final String FROM_CODE = "CMI1";
public static final String TO_CODE = "CMI2";
public static final Double COST = 10.0;
public static final Long CONTAINER_SIZE = 10L;
public static final String ROUTE_TYPE = "ALL";
public static final Long DURATION = 100L;
}

0 comments on commit fad7a9b

Please sign in to comment.