PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/jboss-as-7.1.1.Final/osgi/service/src/test/java/org/jboss/as/osgi/parser/StartLevelHandlerTestCase.java

#
Java | 110 lines | 67 code | 18 blank | 25 comment | 0 complexity | 8247b6ab6da54d479edb20340c8b3d25 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2011, Red Hat, Inc., and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.as.osgi.parser;
  23. import junit.framework.Assert;
  24. import org.jboss.as.controller.OperationContext;
  25. import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
  26. import org.jboss.dmr.ModelNode;
  27. import org.jboss.msc.service.ServiceController;
  28. import org.jboss.msc.service.ServiceRegistry;
  29. import org.jboss.osgi.framework.Services;
  30. import org.junit.Ignore;
  31. import org.junit.Test;
  32. import org.mockito.Mockito;
  33. import org.osgi.service.startlevel.StartLevel;
  34. /**
  35. * @author David Bosschaert
  36. */
  37. //@Ignore("[AS7-3556] Replace mocked subsystem model tests with functional tests")
  38. public class StartLevelHandlerTestCase {
  39. @SuppressWarnings({ "rawtypes", "unchecked" })
  40. @Test
  41. public void testReadHandler() throws Exception {
  42. StartLevel sls = Mockito.mock(StartLevel.class);
  43. Mockito.when(sls.getStartLevel()).thenReturn(999);
  44. ServiceController sc = Mockito.mock(ServiceController.class);
  45. Mockito.when(sc.getValue()).thenReturn(sls);
  46. Mockito.when(sc.getState()).thenReturn(ServiceController.State.UP);
  47. ServiceRegistry sr = Mockito.mock(ServiceRegistry.class);
  48. Mockito.when(sr.getRequiredService(Services.START_LEVEL)).thenReturn(sc);
  49. OperationContext ctx = Mockito.mock(OperationContext.class);
  50. ModelNode result = new ModelNode();
  51. Mockito.when(ctx.getServiceRegistry(false)).thenReturn(sr);
  52. Mockito.when(ctx.getResult()).thenReturn(result);
  53. StartLevelHandler handler = StartLevelHandler.READ_HANDLER;
  54. Assert.assertFalse(result.isDefined());
  55. handler.execute(ctx, new ModelNode());
  56. Assert.assertEquals(999, result.asInt());
  57. }
  58. @SuppressWarnings({ "rawtypes", "unchecked" })
  59. @Test
  60. public void testWriteHandler() throws Exception {
  61. StartLevel sls = Mockito.mock(StartLevel.class);
  62. ServiceController sc = Mockito.mock(ServiceController.class);
  63. Mockito.when(sc.getValue()).thenReturn(sls);
  64. Mockito.when(sc.getState()).thenReturn(ServiceController.State.UP);
  65. ServiceRegistry sr = Mockito.mock(ServiceRegistry.class);
  66. Mockito.when(sr.getRequiredService(Services.START_LEVEL)).thenReturn(sc);
  67. OperationContext ctx = Mockito.mock(OperationContext.class);
  68. Mockito.when(ctx.getServiceRegistry(false)).thenReturn(sr);
  69. ModelNode op = new ModelNode();
  70. op.get(ModelDescriptionConstants.VALUE).set(42);
  71. StartLevelHandler handler = StartLevelHandler.WRITE_HANDLER;
  72. Mockito.verifyZeroInteractions(sls);
  73. handler.execute(ctx, op);
  74. Mockito.verify(sls).setStartLevel(42);
  75. }
  76. @SuppressWarnings({ "rawtypes", "unchecked" })
  77. @Test
  78. public void testSubsystemDown() throws Exception {
  79. ServiceController sc = Mockito.mock(ServiceController.class);
  80. Mockito.when(sc.getState()).thenReturn(ServiceController.State.DOWN);
  81. ServiceRegistry sr = Mockito.mock(ServiceRegistry.class);
  82. Mockito.when(sr.getRequiredService(Services.START_LEVEL)).thenReturn(sc);
  83. ModelNode result = new ModelNode("test");
  84. OperationContext ctx = Mockito.mock(OperationContext.class);
  85. Mockito.when(ctx.getServiceRegistry(false)).thenReturn(sr);
  86. Mockito.when(ctx.getResult()).thenReturn(result);
  87. StartLevelHandler handler = StartLevelHandler.READ_HANDLER;
  88. Assert.assertTrue(result.isDefined());
  89. handler.execute(ctx, new ModelNode());
  90. Assert.assertFalse(result.isDefined());
  91. }
  92. }