+ /**
+ * Add a Volume and an L-Interface Widget to a VF Module via a vserver Widget.
+ *
+ * <li>Create a VF Module</li>
+ * <li>Add a Volume Widget</li>
+ * <li>Add an L-Interface Widget</li>
+ * <li>Add a vserver Widget</li>
+ * <li>Check that both Widgets appear under the vserver</li>
+ */
+ @Test
+ public void testAddVolumeAndLinterfaceWidgetToVf() {
+ VfModule 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
+ */
+ private Widget createNewWidget(Type widgetType) {
+ return Widget.getWidget(widgetType);
+ }
+
+ /**
+ * Create a new VF Module that contains zero widgets and has no members.
+ *
+ * @return new VF Module resource
+ */
+ private VfModule createNewVfModule() {
+ VfModule vfModule = new VfModule();
+ assertNumberOfWidgets(vfModule, 0);
+ return vfModule;
+ }
+
+ /**
+ * Set up some dummy Model Identification properties.
+ *
+ * @param vfModule to be populated
+ */
+ private void populateIdentInfo(VfModule vfModule) {
+ Map<String, String> modelIdentInfo = new HashMap<>();
+ modelIdentInfo.put("UUID", "dummy_uuid");
+ vfModule.populateModelIdentificationInformation(modelIdentInfo);
+ }
+
+ /**
+ * Create a new Widget and assert that it is successfully added to the VF Module.
+ *
+ * @param vfModule the VF Module to update
+ * @param widgetType the type of Widget to create and add
+ */
+ private void assertAddWidget(VfModule vfModule, Type widgetType) {
+ assertThat(createNewWidgetForModule(vfModule, widgetType), is(true));
+ }
+
+ /**
+ * Create a new Widget and assert that it cannot be added to the VF Module.
+ *
+ * @param vfModule the VF Module
+ * @param widgetType the type of Widget to create and attempt to add
+ */
+ private void assertFailToAddWidget(VfModule vfModule, Type widgetType) {
+ assertThat(createNewWidgetForModule(vfModule, widgetType), is(false));
+ }
+
+ /**
+ * Create a new widget, make it a member of the VF Module, then try to add it.
+ *
+ * @param vfModule the VF Module to update
+ * @param widgetType the type of Widget to create and attempt to add
+ * @return whether or not the Widget was added to the module
+ */
+ private boolean createNewWidgetForModule(VfModule vfModule, Type widgetType) {
+ Widget widget = createNewWidget(widgetType);
+ setWidgetAsMember(vfModule, widget);
+ return vfModule.addWidget(widget);
+ }
+
+ /**
+ * Make the specified Widget the sole member of the VF Module. This is achieved by first adding the Widget's own ID
+ * to its set of keys, and by then setting the VF Module's members to a Singleton List comprised of this ID. These
+ * updates allow the Widget to be successfully added to the VF Module. (Non-member Widgets cannot be added.)
+ *
+ * @param vfModule the module for which members are overwritten
+ * @param widget the widget to be set as the member
+ */
+ private void setWidgetAsMember(VfModule vfModule, Widget widget) {