widgetGuid = widget.getIdentifier();
//
// check that the Widget Instance does not yet exist
//
IWidgetInstance widgetInstance = persistenceManager.findWidgetInstanceByGuid(apiKey, "test", "test-shared-data-key", widgetGuid);
assertNull(widgetInstance);
//
// Create the Widget Instance
//
widgetInstance = persistenceManager.newInstance(IWidgetInstance.class);
//
// Set some properties, including preferences
//
widgetInstance.setApiKey(apiKey);
widgetInstance.setWidget(widget);
widgetInstance.setIdKey("test");
widgetInstance.setLang("en");
widgetInstance.setNonce("nonce-test");
widgetInstance.setOpensocialToken("");
widgetInstance.setSharedDataKey("test-shared-data-key");
widgetInstance.setShown(true);
widgetInstance.setUserId("test");
IPreference widgetInstancePreference = persistenceManager.newInstance(IPreference.class);
widgetInstancePreference.setDkey("sharedDataKey");
widgetInstancePreference.setDvalue("test-shared-data-key");
widgetInstancePreference.setReadOnly(true);
widgetInstance.getPreferences().add(widgetInstancePreference);
//
// Save the widget instance
//
persistenceManager.save(widgetInstance);
//
// create a participant
//
IParticipant participant = persistenceManager.newInstance(IParticipant.class);
//participant.setWidget(widget);
participant.setSharedDataKey("test-shared-data-key");
participant.setParticipantId("test");
participant.setParticipantDisplayName("");
participant.setParticipantThumbnailUrl("");
persistenceManager.save(participant);
//
// commit and close persistence manager transaction
//
persistenceManager.commit();
PersistenceManagerFactory.closePersistenceManager();
//
// allocate and begin persistence manager transaction
//
persistenceManager = PersistenceManagerFactory.getPersistenceManager();
persistenceManager.begin();
//
// Get the widget instance created in the previous transaction
//
widgets = persistenceManager.findAll(IWidget.class);
widget = widgets[0];
IWidgetInstance widgetInstance0 = persistenceManager.findWidgetInstanceByGuid(apiKey, "test", "test-shared-data-key", widgetGuid);
assertNotNull(widgetInstance0);
widgetGuid = widget.getIdentifier();
//
// Get the widget instance created in the previous transaction via "widget GUID"
//
IWidgetInstance widgetInstance1 = persistenceManager.findWidgetInstanceByGuid(apiKey, "test", "test-shared-data-key", widgetGuid);
assertNotNull(widgetInstance1);
assertEquals(widgetInstance0, widgetInstance1);
//
// Get the widget instance created in the previous transaction via instance_idkey
//
IWidgetInstance widgetInstance2 = persistenceManager.findWidgetInstanceByIdKey("test");
assertNotNull(widgetInstance2);
assertEquals(widgetInstance0, widgetInstance2);
//
// Get the participant created in the previous transaction by widget instance