Search in sources :

Example 6 with MockNodeService

use of org.jumpmind.symmetric.service.impl.MockNodeService in project symmetric-ds by JumpMind.

the class DefaultNodeIdCreatorTest method testGenerateNodeIdExistingAll.

@Test
public void testGenerateNodeIdExistingAll() throws Exception {
    IParameterService paramService = mock(IParameterService.class);
    Mockito.when(paramService.is(ParameterConstants.EXTERNAL_ID_IS_UNIQUE)).thenReturn(false);
    Mockito.when(paramService.getInt(ParameterConstants.NODE_ID_CREATOR_MAX_NODES, 100)).thenReturn(100);
    DefaultNodeIdCreator generator = new DefaultNodeIdCreator(paramService, new MockNodeService() {

        @Override
        public Node findNode(String nodeId) {
            Node node = new Node();
            node.setNodeId(nodeId);
            return node;
        }
    }, SecurityServiceFactory.create());
    Node node = new Node();
    node.setExternalId("100");
    try {
        generator.generateNodeId(node, null, null);
        fail("Should have received exception");
    } catch (Exception e) {
    // Expected
    }
}
Also used : MockNodeService(org.jumpmind.symmetric.service.impl.MockNodeService) Node(org.jumpmind.symmetric.model.Node) IParameterService(org.jumpmind.symmetric.service.IParameterService) Test(org.junit.Test)

Example 7 with MockNodeService

use of org.jumpmind.symmetric.service.impl.MockNodeService in project symmetric-ds by JumpMind.

the class DefaultNodeIdCreatorTest method testGenerateNodeIdWithNodeIdSet.

@Test
public void testGenerateNodeIdWithNodeIdSet() throws Exception {
    DefaultNodeIdCreator generator = new DefaultNodeIdCreator(new MockParameterService(), new MockNodeService(), SecurityServiceFactory.create());
    Node node = new Node();
    final String EXPECTED_NODE_ID = "10001";
    node.setExternalId(EXPECTED_NODE_ID);
    node.setNodeId(EXPECTED_NODE_ID);
    String selectedNodeId = generator.generateNodeId(node, null, null);
    assertEquals(EXPECTED_NODE_ID, selectedNodeId);
}
Also used : MockNodeService(org.jumpmind.symmetric.service.impl.MockNodeService) MockParameterService(org.jumpmind.symmetric.service.impl.MockParameterService) Node(org.jumpmind.symmetric.model.Node) Test(org.junit.Test)

Example 8 with MockNodeService

use of org.jumpmind.symmetric.service.impl.MockNodeService in project symmetric-ds by JumpMind.

the class DefaultNodeIdCreatorTest method testGenerateNodeIdExisting.

@Test
public void testGenerateNodeIdExisting() throws Exception {
    final String EXPECTED_NODE_ID = "100";
    DefaultNodeIdCreator generator = new DefaultNodeIdCreator(new MockParameterService(ParameterConstants.EXTERNAL_ID_IS_UNIQUE, "true"), new MockNodeService() {

        @Override
        public Node findNode(String nodeId) {
            if (nodeId.equals("100")) {
                Node node = new Node();
                node.setNodeId("100");
                return node;
            } else {
                return null;
            }
        }
    }, SecurityServiceFactory.create());
    Node node = new Node();
    node.setExternalId("100");
    String selectedNodeId = generator.generateNodeId(node, null, null);
    assertEquals(EXPECTED_NODE_ID, selectedNodeId);
}
Also used : MockNodeService(org.jumpmind.symmetric.service.impl.MockNodeService) MockParameterService(org.jumpmind.symmetric.service.impl.MockParameterService) Node(org.jumpmind.symmetric.model.Node) Test(org.junit.Test)

Aggregations

Node (org.jumpmind.symmetric.model.Node)8 MockNodeService (org.jumpmind.symmetric.service.impl.MockNodeService)8 Test (org.junit.Test)8 MockParameterService (org.jumpmind.symmetric.service.impl.MockParameterService)5 IParameterService (org.jumpmind.symmetric.service.IParameterService)3 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)1