/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. import com.nimbits.client.model.diagram.Diagram;
  14. import com.nimbits.client.model.user.User;
  15. import com.nimbits.server.diagram.DiagramModelFactory;
  16. import com.nimbits.server.diagram.DiagramServiceFactory;
  17. import com.nimbits.server.user.UserModelFactory;
  18. import junit.framework.Assert;
  19. import org.junit.Test;
  20. /**
  21. * Created by bsautner
  22. * User: benjamin
  23. * Date: 7/2/11
  24. * Time: 11:04 AM
  25. */
  26. public class TestDiagramServiceImpl {
  27. @Test
  28. public void testDiagramProtectionOwnerRequestsOwnedProtectedDiagram() {
  29. User u = UserModelFactory.createUserModel(1001);
  30. Diagram d = DiagramModelFactory.createDiagramModel(1001);
  31. User diagramOwner = UserModelFactory.createUserModel(1001);
  32. d.setProtectionLevel(0);
  33. // u.addConnection(1002L);
  34. Assert.assertTrue(DiagramServiceFactory.getInstance().checkDiagramProtection(u, diagramOwner, d));
  35. }
  36. @Test
  37. public void testDiagramProtectionLoggedInUserRequestsOthersProtectedDiagram() {
  38. User loggedInUser = UserModelFactory.createUserModel(1001);
  39. User diagramOwner = UserModelFactory.createUserModel(1002);
  40. Diagram d = DiagramModelFactory.createDiagramModel(1002);
  41. d.setProtectionLevel(0);
  42. Assert.assertFalse(DiagramServiceFactory.getInstance().checkDiagramProtection(loggedInUser, diagramOwner, d));
  43. }
  44. @Test
  45. public void testDiagramProtectionOwnerRequestsConnectionsProtectedDiagram() {
  46. User u = UserModelFactory.createUserModel(1001);
  47. Diagram d = DiagramModelFactory.createDiagramModel(1002);
  48. User diagramOwner = UserModelFactory.createUserModel(1002);
  49. d.setProtectionLevel(0);
  50. diagramOwner.addConnection(1001L);
  51. Assert.assertFalse(DiagramServiceFactory.getInstance().checkDiagramProtection(u, diagramOwner, d));
  52. }
  53. @Test
  54. public void testDiagramProtectionOwnerRequestsConnectionsSharedDiagram() {
  55. User loggedInUser = UserModelFactory.createUserModel(1001L);
  56. Diagram d = DiagramModelFactory.createDiagramModel(1002);
  57. User diagramOwner = UserModelFactory.createUserModel(1002);
  58. d.setProtectionLevel(1);
  59. diagramOwner.addConnection(1001L);
  60. Assert.assertTrue("connection accessing shared diagram", DiagramServiceFactory.getInstance().checkDiagramProtection(loggedInUser, diagramOwner, d));
  61. }
  62. @Test
  63. public void testDiagramProtectionOwnerRequestsNotInConnectionsSharedDiagram() {
  64. User loggedInUser = UserModelFactory.createUserModel(1001L);
  65. Diagram d = DiagramModelFactory.createDiagramModel(1002);
  66. User diagramOwner = UserModelFactory.createUserModel(1002);
  67. d.setProtectionLevel(1);
  68. // diagramOwner.addConnection(1001L);
  69. Assert.assertFalse("accessing shared diagram but not a connection", DiagramServiceFactory.getInstance().checkDiagramProtection(loggedInUser, diagramOwner, d));
  70. }
  71. @Test
  72. public void testDiagramProtectionOwnerRequestsConnectionsPublicDiagram() {
  73. User loggedInUser = UserModelFactory.createUserModel(1001L);
  74. Diagram d = DiagramModelFactory.createDiagramModel(1002);
  75. User diagramOwner = UserModelFactory.createUserModel(1002);
  76. d.setProtectionLevel(2);
  77. // diagramOwner.addConnection(1001L);
  78. Assert.assertTrue("connection accessing public diagram", DiagramServiceFactory.getInstance().checkDiagramProtection(loggedInUser, diagramOwner, d));
  79. }
  80. @Test
  81. public void testDiagramProtectionLoggedInUserRequestsOthersSharedDiagram() {
  82. User loggedInUser = UserModelFactory.createUserModel(1001);
  83. User diagramOwner = UserModelFactory.createUserModel(1002);
  84. Diagram d = DiagramModelFactory.createDiagramModel(1002);
  85. d.setProtectionLevel(1);
  86. Assert.assertFalse(DiagramServiceFactory.getInstance().checkDiagramProtection(loggedInUser, diagramOwner, d));
  87. }
  88. @Test
  89. public void testDiagramProtectionLoggedInUserRequestsConnectionsProtectedDiagram() {
  90. User u = UserModelFactory.createUserModel(1001);
  91. Diagram d = DiagramModelFactory.createDiagramModel(1002);
  92. User diagramOwner = UserModelFactory.createUserModel(1002);
  93. d.setProtectionLevel(0);
  94. u.addConnection(1003L);
  95. u.addConnection(1002L);
  96. Assert.assertFalse(DiagramServiceFactory.getInstance().checkDiagramProtection(u, diagramOwner, d));
  97. }
  98. }