+ public void testAddVolumeAndLinterfaceWidgetToVf() throws XmlArtifactGenerationException {
+ Resource vfModule = createNewVfModule();
+
+ // Adding a Volume widget has no effect until a vserver widget is added.
+ assertAddWidget(vfModule, Type.VOLUME);
+ assertNumberOfWidgets(vfModule, 0);
+
+ // Adding an L-Interface widget has no effect until a vserver widget is added.
+ assertFailToAddWidget(vfModule, Type.LINT);
+ assertNumberOfWidgets(vfModule, 0);
+
+ final int vserverBaseWidgetCount = createVserverForVf(vfModule);
+
+ // The vserver now has both Volume and L-Interface.
+ assertNumberOfWidgets(vfModule.vserver, vserverBaseWidgetCount + 2);
+
+ // Adding another instance of a vserver widget fails.
+ assertFailToAddWidget(vfModule, Type.VSERVER);
+ assertNumberOfWidgets(vfModule, 1);
+
+ // Add new instances (with no effect).
+ assertAddWidget(vfModule, Type.VOLUME);
+ assertAddWidget(vfModule, Type.LINT);
+ // Assert that no additional Widgets are in fact present.
+ assertNumberOfWidgets(vfModule, 1);
+ assertNumberOfWidgets(vfModule.vserver, vserverBaseWidgetCount + 2);
+ }
+
+ private void assertNumberOfWidgets(Model model, int numberOfWidgets) {
+ assertThat(model.getWidgets(), hasSize(numberOfWidgets));
+ }
+
+ /**
+ * Use the static Factory method to create a new Widget.
+ *
+ * @param widgetType
+ * type of Widget to create
+ * @return a new Widget
+ * @throws XmlArtifactGenerationException
+ * if the Widget mapping configuration is missing
+ */
+ private Widget createNewWidget(Type widgetType) throws XmlArtifactGenerationException {
+ return Widget.getWidget(widgetType);
+ }
+
+ /**
+ * Create a new VF Module that contains zero widgets and has no members.
+ *
+ * @return new VF Module resource
+ */
+ private Resource createNewVfModule() {
+ Resource vfModule = new Resource(Type.VFMODULE, true);
+ assertNumberOfWidgets(vfModule, 0);
+ return vfModule;
+ }
+
+ /**
+ * Set up some dummy Model Identification properties.
+ *
+ * @param vfModule
+ * to be populated
+ */
+ private void populateIdentInfo(Resource vfModule) {
+ Map<String, String> modelIdentInfo = new HashMap<>();
+ modelIdentInfo.put("UUID", "dummy_uuid");
+ vfModule.populateModelIdentificationInformation(modelIdentInfo);