forked from eclipse/vorto
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: shiv12095 <shiv12095@iiitd.ac.in>
- Loading branch information
Showing
8 changed files
with
148 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
.../src/test/java/org/eclipse/vorto/server/devtool/service/ProjectRepositoryServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.eclipse.vorto.server.devtool.service; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.eclipse.vorto.editor.web.resource.WebEditorResourceSetProvider; | ||
import org.eclipse.vorto.server.devtool.exception.ProjectAlreadyExistsException; | ||
import org.eclipse.vorto.server.devtool.exception.ProjectNotFoundException; | ||
import org.eclipse.vorto.server.devtool.service.impl.ProjectRepositoryServiceImpl; | ||
import org.eclipse.xtext.web.server.model.IWebResourceSetProvider; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
import com.google.inject.Injector; | ||
|
||
public class ProjectRepositoryServiceTest { | ||
|
||
@InjectMocks | ||
private IProjectRepositoryService projectRepositoryService = new ProjectRepositoryServiceImpl(); | ||
|
||
@Mock | ||
private IProjectRespositoryDAO projectRespositoryDAO; | ||
|
||
@Mock | ||
private Injector injector; | ||
|
||
@Mock | ||
private WebEditorResourceSetProvider webEditorResourceSetProvider; | ||
|
||
private String sessionId = "sessionId"; | ||
private String projectName = "Project"; | ||
|
||
@Before | ||
public void initMocks() { | ||
MockitoAnnotations.initMocks(this); | ||
} | ||
|
||
@Test(expected = ProjectAlreadyExistsException.class) | ||
public void checkProjectExistsTest() throws ProjectAlreadyExistsException{ | ||
when(injector.getInstance(IWebResourceSetProvider.class)).thenReturn(webEditorResourceSetProvider); | ||
when(projectRespositoryDAO.projectExists(projectName, sessionId)).thenReturn(true); | ||
projectRepositoryService.createProject(sessionId, projectName); | ||
} | ||
|
||
@Test(expected = ProjectNotFoundException.class) | ||
public void openNonExistantProjectTest() throws ProjectNotFoundException{ | ||
when(projectRespositoryDAO.openProject(projectName, sessionId)).thenReturn(null); | ||
projectRepositoryService.openProject(sessionId, projectName); | ||
} | ||
|
||
@Test | ||
public void getProjectListTest() throws ProjectNotFoundException{ | ||
assertNotNull(projectRepositoryService.getProjects(sessionId)); | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...src/test/java/org/eclipse/vorto/server/devtool/service/impl/ProjectRepositoryDAOTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.eclipse.vorto.server.devtool.service.impl; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.eclipse.vorto.server.devtool.models.Project; | ||
import org.junit.Test; | ||
import org.mockito.InjectMocks; | ||
|
||
public class ProjectRepositoryDAOTest { | ||
|
||
@InjectMocks | ||
private MapProjectRespositoryDAOImpl projectRepositoryDAO = new MapProjectRespositoryDAOImpl(); | ||
|
||
private String sessionId = "sessionId"; | ||
private String projectName = "Project"; | ||
|
||
@Test | ||
public void uniqueProjectNameTest(){ | ||
Project project1 = new Project(projectName); | ||
projectRepositoryDAO.createProject(project1, sessionId); | ||
assertEquals(1, projectRepositoryDAO.getProjects(sessionId).size()); | ||
Project project2 = new Project(projectName); | ||
projectRepositoryDAO.createProject(project2, sessionId); | ||
assertEquals(1, projectRepositoryDAO.getProjects(sessionId).size()); | ||
} | ||
|
||
@Test | ||
public void checkProjectExistsTest(){ | ||
Project project1 = new Project(projectName); | ||
projectRepositoryDAO.createProject(project1, sessionId); | ||
assertTrue(projectRepositoryDAO.projectExists(projectName, sessionId)); | ||
assertFalse(projectRepositoryDAO.projectExists(Long.toString(System.currentTimeMillis()), sessionId)); | ||
} | ||
|
||
|
||
@Test | ||
public void openProjectTest(){ | ||
Project project1 = new Project(projectName); | ||
projectRepositoryDAO.createProject(project1, sessionId); | ||
assertNotNull(projectRepositoryDAO.openProject(projectName, sessionId)); | ||
assertNull((projectRepositoryDAO.openProject(Long.toString(System.currentTimeMillis()), sessionId))); | ||
} | ||
|
||
@Test | ||
public void getProjectsTest(){ | ||
Project project1 = new Project(projectName); | ||
projectRepositoryDAO.createProject(project1, sessionId); | ||
assertEquals(1, projectRepositoryDAO.getProjects(sessionId).size()); | ||
assertEquals(projectName, projectRepositoryDAO.getProjects(sessionId).get(0).getProjectName()); | ||
} | ||
|
||
} |