assertNotNull(widgetServices);
assertEquals(5, widgetServices.length);
// test generic findById methods
Object widgetId = allWidgets[0].getId();
IWidget widgetById = persistenceManager.findById(IWidget.class, widgetId);
assertNotNull(widgetById);
assertEquals(allWidgets[0], widgetById);
Object widgetDefaultId = allWidgetDefaults[0].getId();
IWidgetDefault widgetDefaultById = persistenceManager.findById(IWidgetDefault.class, widgetDefaultId);
assertNotNull(widgetDefaultById);
assertEquals(allWidgetDefaults[0], widgetDefaultById);
// test generic findByValue methods
String widgetGuid = allWidgets[0].getGuid();
IWidget [] widgetsByValue = persistenceManager.findByValue(IWidget.class, "guid", widgetGuid);
assertNotNull(widgetsByValue);
assertEquals(1, widgetsByValue.length);
assertEquals(allWidgets[0], widgetsByValue[0]);
IWidgetDefault [] widgetDefaultsByValue = persistenceManager.findByValue(IWidgetDefault.class, "widget", widgetById);
assertNotNull(widgetDefaultsByValue);
assertEquals(1, widgetDefaultsByValue.length);
assertEquals(allWidgetDefaults[0], widgetDefaultsByValue[0]);
// test generic findByValues methods
Map<String,Object> values = new HashMap<String,Object>();
values.put("height", allWidgets[0].getHeight());
values.put("width", allWidgets[0].getWidth());
values.put("widgetAuthor", allWidgets[0].getWidgetAuthor());
IWidget [] widgetsByValues = persistenceManager.findByValues(IWidget.class, values);
assertNotNull(widgetsByValues);
assertEquals(1, widgetsByValues.length);
assertEquals(allWidgets[0], widgetsByValues[0]);
// test custom widget query methods
IWidget widgetByGuid = persistenceManager.findWidgetByGuid(widgetGuid);
assertNotNull(widgetByGuid);
assertEquals(allWidgets[0], widgetByGuid);
String widgetContext = allWidgetDefaults[0].getWidgetContext();
IWidget widgetDefaultByType = persistenceManager.findWidgetDefaultByType(widgetContext);
assertNotNull(widgetDefaultByType);
assertEquals(allWidgets[0], widgetDefaultByType);
IWidget [] widgetsByType = persistenceManager.findWidgetsByType(widgetContext);
assertNotNull(widgetsByType);
assertEquals(1, widgetsByType.length);
assertEquals(allWidgets[0], widgetsByType[0]);
// rollback and close persistence manager transaction
persistenceManager.rollback();
PersistenceManagerFactory.closePersistenceManager();
// allocate and begin persistence manager transaction
persistenceManager = PersistenceManagerFactory.getPersistenceManager();
persistenceManager.begin();
// create widget instance
IApiKey [] apiKeys = persistenceManager.findAll(IApiKey.class);
String apiKey = apiKeys[0].getValue();
IWidget [] widgets = persistenceManager.findAll(IWidget.class);
IWidget widget = widgets[0];
widgetGuid = widget.getGuid();
IWidgetInstance widgetInstance = persistenceManager.findWidgetInstanceByGuid(apiKey, "test", "test-shared-data-key", widgetGuid);
assertNull(widgetInstance);
widgetInstance = persistenceManager.newInstance(IWidgetInstance.class);
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);
persistenceManager.save(widgetInstance);
// create 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);
// create server feature
IServerFeature serverFeature = persistenceManager.newInstance(IServerFeature.class);
serverFeature.setFeatureName("test-feature-name");
serverFeature.setClassName("test.feature.class.name");
persistenceManager.save(serverFeature);
// create access request
IAccessRequest accessRequest = persistenceManager.newInstance(IAccessRequest.class);
accessRequest.setOrigin("localhost");
accessRequest.setSubdomains(false);
accessRequest.setGranted(true);
accessRequest.setWidget(widget);
persistenceManager.save(accessRequest);
// commit and close persistence manager transaction
persistenceManager.commit();
PersistenceManagerFactory.closePersistenceManager();
// allocate and begin persistence manager transaction
persistenceManager = PersistenceManagerFactory.getPersistenceManager();
persistenceManager.begin();
// test custom widget instance query methods
apiKeys = persistenceManager.findAll(IApiKey.class);
apiKey = apiKeys[0].getValue();
widgets = persistenceManager.findAll(IWidget.class);
widget = widgets[0];
String serviceContext = widget.getWidgetTypes().iterator().next().getWidgetContext();
IWidgetInstance widgetInstance0 = persistenceManager.findWidgetInstance(apiKey, "test", "test-shared-data-key", serviceContext);
assertNotNull(widgetInstance0);
widgetGuid = widget.getGuid();
IWidgetInstance widgetInstance1 = persistenceManager.findWidgetInstanceByGuid(apiKey, "test", "test-shared-data-key", widgetGuid);
assertNotNull(widgetInstance1);
assertEquals(widgetInstance0, widgetInstance1);
IWidgetInstance widgetInstance2 = persistenceManager.findWidgetInstanceByIdKey("test");
assertNotNull(widgetInstance2);