PageRenderTime 13ms CodeModel.GetById 1ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/v3.2/nimbits-tds/test/TestDiagramServiceImpl.java

http://nimbits-server.googlecode.com/
Java | 112 lines | 77 code | 14 blank | 21 comment | 0 complexity | 89c6365886d72af4b01686ab2195fdbf MD5 | raw file
  1/*
  2 * Copyright (c) 2010 Tonic Solutions LLC.
  3 *
  4 * http://www.nimbits.com
  5 *
  6 *
  7 * Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
  8 *
  9 * http://www.gnu.org/licenses/gpl.html
 10 *
 11 * Unless required by applicable law or agreed to in writing, software distributed under the license is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 12 */
 13
 14import com.nimbits.client.model.diagram.Diagram;
 15import com.nimbits.client.model.user.User;
 16import com.nimbits.server.diagram.DiagramModelFactory;
 17import com.nimbits.server.diagram.DiagramServiceFactory;
 18import com.nimbits.server.user.UserModelFactory;
 19import junit.framework.Assert;
 20import org.junit.Test;
 21
 22/**
 23 * Created by bsautner
 24 * User: benjamin
 25 * Date: 7/2/11
 26 * Time: 11:04 AM
 27 */
 28public class TestDiagramServiceImpl {
 29
 30
 31    @Test
 32    public void testDiagramProtectionOwnerRequestsOwnedProtectedDiagram() {
 33        User u = UserModelFactory.createUserModel(1001);
 34        Diagram d = DiagramModelFactory.createDiagramModel(1001);
 35        User diagramOwner = UserModelFactory.createUserModel(1001);
 36        d.setProtectionLevel(0);
 37        //  u.addConnection(1002L);
 38        Assert.assertTrue(DiagramServiceFactory.getInstance().checkDiagramProtection(u, diagramOwner, d));
 39    }
 40
 41    @Test
 42    public void testDiagramProtectionLoggedInUserRequestsOthersProtectedDiagram() {
 43        User loggedInUser = UserModelFactory.createUserModel(1001);
 44        User diagramOwner = UserModelFactory.createUserModel(1002);
 45        Diagram d = DiagramModelFactory.createDiagramModel(1002);
 46        d.setProtectionLevel(0);
 47        Assert.assertFalse(DiagramServiceFactory.getInstance().checkDiagramProtection(loggedInUser, diagramOwner, d));
 48    }
 49
 50    @Test
 51    public void testDiagramProtectionOwnerRequestsConnectionsProtectedDiagram() {
 52        User u = UserModelFactory.createUserModel(1001);
 53        Diagram d = DiagramModelFactory.createDiagramModel(1002);
 54        User diagramOwner = UserModelFactory.createUserModel(1002);
 55        d.setProtectionLevel(0);
 56        diagramOwner.addConnection(1001L);
 57        Assert.assertFalse(DiagramServiceFactory.getInstance().checkDiagramProtection(u, diagramOwner, d));
 58    }
 59
 60    @Test
 61    public void testDiagramProtectionOwnerRequestsConnectionsSharedDiagram() {
 62        User loggedInUser = UserModelFactory.createUserModel(1001L);
 63        Diagram d = DiagramModelFactory.createDiagramModel(1002);
 64        User diagramOwner = UserModelFactory.createUserModel(1002);
 65        d.setProtectionLevel(1);
 66        diagramOwner.addConnection(1001L);
 67        Assert.assertTrue("connection accessing shared diagram", DiagramServiceFactory.getInstance().checkDiagramProtection(loggedInUser, diagramOwner, d));
 68    }
 69
 70    @Test
 71    public void testDiagramProtectionOwnerRequestsNotInConnectionsSharedDiagram() {
 72        User loggedInUser = UserModelFactory.createUserModel(1001L);
 73        Diagram d = DiagramModelFactory.createDiagramModel(1002);
 74        User diagramOwner = UserModelFactory.createUserModel(1002);
 75        d.setProtectionLevel(1);
 76        //  diagramOwner.addConnection(1001L);
 77        Assert.assertFalse("accessing shared diagram but not a connection", DiagramServiceFactory.getInstance().checkDiagramProtection(loggedInUser, diagramOwner, d));
 78    }
 79
 80    @Test
 81    public void testDiagramProtectionOwnerRequestsConnectionsPublicDiagram() {
 82        User loggedInUser = UserModelFactory.createUserModel(1001L);
 83        Diagram d = DiagramModelFactory.createDiagramModel(1002);
 84        User diagramOwner = UserModelFactory.createUserModel(1002);
 85        d.setProtectionLevel(2);
 86        //  diagramOwner.addConnection(1001L);
 87        Assert.assertTrue("connection accessing public diagram", DiagramServiceFactory.getInstance().checkDiagramProtection(loggedInUser, diagramOwner, d));
 88    }
 89
 90
 91    @Test
 92    public void testDiagramProtectionLoggedInUserRequestsOthersSharedDiagram() {
 93        User loggedInUser = UserModelFactory.createUserModel(1001);
 94        User diagramOwner = UserModelFactory.createUserModel(1002);
 95        Diagram d = DiagramModelFactory.createDiagramModel(1002);
 96        d.setProtectionLevel(1);
 97        Assert.assertFalse(DiagramServiceFactory.getInstance().checkDiagramProtection(loggedInUser, diagramOwner, d));
 98    }
 99
100    @Test
101    public void testDiagramProtectionLoggedInUserRequestsConnectionsProtectedDiagram() {
102        User u = UserModelFactory.createUserModel(1001);
103        Diagram d = DiagramModelFactory.createDiagramModel(1002);
104        User diagramOwner = UserModelFactory.createUserModel(1002);
105        d.setProtectionLevel(0);
106        u.addConnection(1003L);
107        u.addConnection(1002L);
108        Assert.assertFalse(DiagramServiceFactory.getInstance().checkDiagramProtection(u, diagramOwner, d));
109
110    }
111
112}