package com.altamiracorp.lumify.web.routes.vertex;

import com.altamiracorp.lumify.core.model.graph.GraphRepository;
import com.altamiracorp.lumify.core.user.User;
import com.altamiracorp.lumify.web.AuthenticationProvider;
import com.altamiracorp.lumify.web.routes.RouteTestBase;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import javax.servlet.http.HttpSession;

import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class VertexRelationshipRemovalTest extends RouteTestBase {
    private VertexRelationshipRemoval vertexRelationshipRemoval;

    @Mock
    private GraphRepository mockGraphRepository;
    @Mock
    private User mockUser;
    @Mock
    private HttpSession mockHttpSession;

    @Override
    @Before
    public void setUp() throws Exception {
        super.setUp();
        vertexRelationshipRemoval = new VertexRelationshipRemoval(mockGraphRepository);
    }

    @Test
    public void testHandle() throws Exception {
        when(mockRequest.getParameter("sourceId")).thenReturn("sourceId");
        when(mockRequest.getParameter("targetId")).thenReturn("targetId");
        when(mockRequest.getParameter("label")).thenReturn("label");

        when(mockRequest.getSession()).thenReturn(mockHttpSession);
        when(AuthenticationProvider.getUser(mockHttpSession)).thenReturn(mockUser);

        vertexRelationshipRemoval.handle(mockRequest, mockResponse, mockHandlerChain);
        JSONObject response = new JSONObject(responseStringWriter.getBuffer().toString());
        assertTrue(response.getBoolean("success"));
    }
}

@@ -91,29 +91,216 @@
 del.
-graph.GraphRepository
+audit.AuditAction;%0Aimport com.altamiracorp.lumify.core.model.audit.AuditRepository;%0Aimport com.altamiracorp.lumify.core.model.graph.GraphRepository;%0Aimport com.altamiracorp.lumify.core.model.graph.GraphVertex
 ;%0Aim
@@ -725,16 +725,99 @@
 rtTrue;%0A
+import static org.mockito.Mockito.times;%0Aimport static org.mockito.Mockito.verify;%0A
 import s
@@ -1078,32 +1078,91 @@
 tory;%0A    @Mock%0A
+    private AuditRepository mockAuditRepository;%0A    @Mock%0A
     private User
@@ -1222,16 +1222,118 @@
 Session;
+%0A    @Mock%0A    private GraphVertex mockSourceVertex;%0A    @Mock%0A    private GraphVertex mockDestVertex;
 %0A%0A    @O
@@ -1503,16 +1503,37 @@
 pository
+, mockAuditRepository
 );%0A    %7D
@@ -1963,16 +1963,208 @@
 ckUser);
+%0A        when(mockGraphRepository.findVertex(%22sourceId%22, mockUser)).thenReturn(mockSourceVertex);%0A        when(mockGraphRepository.findVertex(%22targetId%22, mockUser)).thenReturn(mockDestVertex);
 %0A%0A      
@@ -2386,16 +2386,175 @@
 cess%22));
+%0A%0A        verify(mockAuditRepository, times(1)).auditRelationships(AuditAction.DELETE.toString(), mockSourceVertex, mockDestVertex, %22label%22, %22%22, %22%22, mockUser);
 %0A    %7D%0A%7D

fix test