Configuration pluginConfig = new Configuration();
Configuration jobsConfig = new Configuration();
pluginConfig.put(new PropertySimple("first", "last"));
jobsConfig.put(new PropertySimple("aaa", "bbb"));
ServerPlugin plugin = new ServerPlugin(name, path);
plugin.setDisplayName(displayName);
plugin.setEnabled(enabled);
plugin.setMD5(md5);
plugin.setVersion(version);
plugin.setAmpsVersion(ampsVersion);
plugin.setDescription(description);
plugin.setHelp(help);
plugin.setContent(content);
plugin.setDeployment(deployment);
plugin.setPluginConfiguration(pluginConfig);
plugin.setScheduledJobsConfiguration(jobsConfig);
plugin.setType(type);
em.persist(plugin);
assert plugin.getId() > 0;
plugin = em.find(ServerPlugin.class, plugin.getId());
assert plugin != null;
assert plugin.getId() > 0;
assert plugin.getName().equals(name);
assert plugin.getPath().equals(path);
assert plugin.getDisplayName().equals(displayName);
assert plugin.isEnabled() == enabled;
assert plugin.getMD5().equals(md5);
assert plugin.getVersion().equals(version);
assert plugin.getAmpsVersion().equals(ampsVersion);
assert plugin.getDescription().equals(description);
assert plugin.getDeployment() == deployment;
assert plugin.getPluginConfiguration().equals(pluginConfig);
assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
assert plugin.getHelp().equals(help);
assert plugin.getType().equals(type);
assert new String(plugin.getContent()).equals(new String(content));
// test our queries that purposefully do not load in the content blob
query = em.createNamedQuery(ServerPlugin.QUERY_FIND_BY_NAME);
query.setParameter("name", name);
plugin = (ServerPlugin) query.getSingleResult();
assert plugin != null;
assert plugin.getId() > 0;
assert plugin.getName().equals(name);
assert plugin.getPath().equals(path);
assert plugin.getDisplayName().equals(displayName);
assert plugin.isEnabled() == enabled;
assert plugin.getMD5().equals(md5);
assert plugin.getVersion().equals(version);
assert plugin.getAmpsVersion().equals(ampsVersion);
assert plugin.getDescription().equals(description);
assert plugin.getDeployment() == deployment;
assert plugin.getPluginConfiguration().equals(pluginConfig);
assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
assert plugin.getHelp().equals(help);
assert plugin.getType().equals(type);
assert plugin.getContent() == null;
query = em.createNamedQuery(ServerPlugin.QUERY_FIND_BY_IDS);
query.setParameter("ids", Arrays.asList(Integer.valueOf(plugin.getId())));
plugin = (ServerPlugin) query.getSingleResult();
assert plugin != null;
assert plugin.getId() > 0;
assert plugin.getName().equals(name);
assert plugin.getPath().equals(path);
assert plugin.getDisplayName().equals(displayName);
assert plugin.isEnabled() == enabled;
assert plugin.getMD5().equals(md5);
assert plugin.getVersion().equals(version);
assert plugin.getAmpsVersion().equals(ampsVersion);
assert plugin.getDescription().equals(description);
assert plugin.getDeployment() == deployment;
assert plugin.getPluginConfiguration().equals(pluginConfig);
assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
assert plugin.getHelp().equals(help);
assert plugin.getType().equals(type);
assert plugin.getContent() == null;
query = em.createNamedQuery(ServerPlugin.QUERY_FIND_ALL_INSTALLED);
List<ServerPlugin> all = query.getResultList();
boolean got_it = false;
for (ServerPlugin p : all) {
if (p.getName().equals(name)) {
got_it = true;
assert p.getId() > 0;
assert p.getName().equals(name);
assert p.getPath().equals(path);
assert p.getDisplayName().equals(displayName);
assert p.isEnabled() == enabled;
assert p.getMD5().equals(md5);
assert p.getVersion().equals(version);
assert plugin.getAmpsVersion().equals(ampsVersion);
assert p.getDescription().equals(description);
assert plugin.getDeployment() == deployment;
assert plugin.getPluginConfiguration().equals(pluginConfig);
assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
assert p.getHelp().equals(help);
assert plugin.getType().equals(type);
assert p.getContent() == null;
break;
}
}
assert got_it : "findAll query failed to get our plugin";
query = em.createNamedQuery(ServerPlugin.QUERY_FIND_ALL_INSTALLED_KEYS);
List<PluginKey> allKeys = query.getResultList();
assert allKeys.size() == originalNumberOfPlugins + 1;
assert allKeys.contains(new PluginKey(plugin));
query = em.createNamedQuery(ServerPlugin.QUERY_FIND_KEYS_BY_IDS);
ArrayList<Integer> ids = new ArrayList<Integer>();
ids.add(plugin.getId());
query.setParameter("ids", ids);
allKeys = query.getResultList();
assert allKeys.size() == 1;
assert allKeys.contains(new PluginKey(plugin));
query = em.createNamedQuery(ServerPlugin.QUERY_GET_CONFIG_MTIMES);
query.setParameter("id", plugin.getId());
Object[] times = (Object[]) query.getSingleResult();
assert times[0] != null;
assert times[1] != null;
assert ((Long) times[0]).longValue() > 0;
assert ((Long) times[1]).longValue() > 0;
// mark a plugin deleted - all of our queries should then never see it
plugin.setStatus(PluginStatusType.DELETED);
em.merge(plugin);
query = em.createNamedQuery(ServerPlugin.QUERY_FIND_BY_NAME);
query.setParameter("name", name);
List<?> results = query.getResultList();
assert results.size() == 0;
query = em.createNamedQuery(ServerPlugin.QUERY_FIND_BY_IDS);
query.setParameter("ids", Arrays.asList(Integer.valueOf(plugin.getId())));
results = query.getResultList();
assert results.size() == 0;
query = em.createNamedQuery(ServerPlugin.QUERY_FIND_ALL_INSTALLED);
results = query.getResultList();