/patching/src/test/java/org/jboss/as/patching/tests/PatchConflictsUnitTestCase.java

https://github.com/robertpanzer/jboss-as · Java · 88 lines · 48 code · 13 blank · 27 comment · 0 complexity · 1168d943b6a8fb7d491e4883aa07cf0e MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2013, 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.patching.tests;
  23. import static org.jboss.as.patching.Constants.BASE;
  24. import static org.jboss.as.patching.IoUtils.NO_CONTENT;
  25. import static org.jboss.as.patching.runner.TestUtils.createModule0;
  26. import static org.jboss.as.patching.runner.TestUtils.randomString;
  27. import static org.jboss.as.patching.tool.PatchTool.Factory.policyBuilder;
  28. import java.io.File;
  29. import org.jboss.as.patching.metadata.ModuleItem;
  30. import org.jboss.as.patching.ContentConflictsException;
  31. import org.jboss.as.patching.tool.ContentVerificationPolicy;
  32. import org.junit.Assert;
  33. import org.junit.Test;
  34. /**
  35. * @author Emanuel Muckenhuber
  36. */
  37. public class PatchConflictsUnitTestCase extends AbstractPatchingTest {
  38. @Test
  39. public void testOverrideModules() throws Exception {
  40. testModuleConflicts(policyBuilder().ignoreModuleChanges().createPolicy());
  41. }
  42. @Test
  43. public void testOverrideAllImpliesOverrideModules() throws Exception {
  44. // Override-all should also imply override modules
  45. testModuleConflicts(policyBuilder().overrideAll().createPolicy());
  46. }
  47. @Test
  48. public void testModuleOverrideAndRollback() throws Exception {
  49. final PatchingTestStepBuilder step = testModuleConflicts(policyBuilder().overrideAll().createPolicy());
  50. rollback(step);
  51. }
  52. protected PatchingTestStepBuilder testModuleConflicts(final ContentVerificationPolicy resolvePolicy) throws Exception {
  53. final PatchingTestBuilder builder = createDefaultBuilder();
  54. final byte[] moduleHash = new byte[20];
  55. // Create a conflict
  56. final File base = builder.getFile("modules", "system", "layers", "base");
  57. createModule0(base, "org.jboss.test", randomString());
  58. final PatchingTestStepBuilder oneOff1 = builder.createStepBuilder();
  59. oneOff1.setPatchId("one-off-1")
  60. .oneOffPatchIdentity(PRODUCT_VERSION)
  61. .oneOffPatchElement("base-oo1", BASE, false)
  62. .updateModuleWithRandomContent("org.jboss.test", NO_CONTENT, moduleHash)
  63. ;
  64. try {
  65. apply(oneOff1);
  66. Assert.fail("should have detected conflicts");
  67. } catch (ContentConflictsException expected) {
  68. final ModuleItem item = new ModuleItem("org.jboss.test", "main", moduleHash);
  69. Assert.assertTrue(expected.getConflicts().contains(item));
  70. }
  71. // Apply patch and override all
  72. apply(oneOff1, resolvePolicy);
  73. return oneOff1;
  74. }
  75. }