package net.powermatcher.test.osgi;

import junit.framework.TestCase;
import net.powermatcher.core.auctioneer.Auctioneer;

import org.apache.felix.scr.ScrService;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
import org.osgi.service.cm.ConfigurationAdmin;
import org.apache.felix.scr.Component;

public class AgentTest extends TestCase {

    private final BundleContext context = FrameworkUtil.getBundle(this.getClass()).getBundleContext();

    private ConfigurationAdmin configAdmin;
    private ServiceReference<?> configAdminReference;
    private ScrService scrService;
    private ServiceReference scrServiceReference; 
    
	public void testExample() throws Exception {
		super.setUp();
		
		configAdminReference = context.getServiceReference(ConfigurationAdmin.class.getName());
    	if (configAdminReference != null) {
    		configAdmin = (ConfigurationAdmin) context.getService(configAdminReference);
    	}
    	assert(configAdmin != null);
    	assertNotNull(configAdmin);
    	
    	scrServiceReference = context.getServiceReference( ScrService.class.getName() );
    	if (scrServiceReference != null) {
    		scrService = (ScrService) context.getService(scrServiceReference);
    	}

    	assertNotNull(scrService);
    	
    	// Check if the ConfigManager is present
    	Component[] components = scrService.getComponents("net.powermatcher.core.config.management.agent.ConfigManager");
    }
	
}

@@ -30,16 +30,74 @@
 .osgi;%0A%0A
+import java.util.Dictionary;%0Aimport java.util.Hashtable;%0A%0A
 import j
@@ -172,16 +172,127 @@
 tioneer;
+%0Aimport net.powermatcher.test.helpers.PropertieBuilder;%0Aimport net.powermatcher.test.helpers.TestClusterHelper;
 %0A%0Aimport
@@ -447,24 +447,66 @@
 eReference;%0A
+import org.osgi.service.cm.Configuration;%0A
 import org.o
@@ -888,16 +888,19 @@
 eference
+%3C?%3E
  scrServ
@@ -912,17 +912,62 @@
 ference;
- 
+%0A    %0A    //private TestClusterHelper cluster;
 %0A    %0A%09p
@@ -1255,42 +1255,8 @@
  %09%7D%0A
-    %09assert(configAdmin != null);%0A
     
@@ -1586,16 +1586,18 @@
 nt%0A    %09
+//
 Componen
@@ -1665,48 +1665,1856 @@
 ore.
-config.management.agent.ConfigManager%22);
+auctioneer.Auctioneer%22);%0A    %09Component%5B%5D components = scrService.getComponents();%0A    %09%0A    %09// create Auctioneer props%0A    %09String pid = %22net.powermatcher.core.auctioneer%22;%0A    %09String factoryPid = %22net.powermatcher.core.auctioneer.Auctioneer%22;%0A    %09Dictionary%3CString, Object%3E properties = new Hashtable%3CString, Object%3E();%0A    %09properties.put(%22agentId%22, %22auctioneer%22);%0A    %09properties.put(%22clusterId%22, %22DefaultCluster%22);%0A    %09properties.put(%22commodity%22, %22electricity%22);%0A    %09properties.put(%22currency%22, %22EUR%22);%0A    %09properties.put(%22priceSteps%22, %22100%22);%0A    %09properties.put(%22maximumPrice%22, %221%22);%0A    %09properties.put(%22bidTimeout%22, %22600%22);%0A    %09properties.put(%22priceUpdateRate%22, %2230%22);%0A    %09%0A    %09Configuration config = this.configAdmin.getConfiguration(pid, null);%0A    %09this.configAdmin.createFactoryConfiguration(factoryPid);%0A%0A    %09if (config != null) %7B%0A%09%09%09config.update(properties);%0A%09%09%7D%0A    %09%0A    %09Configuration configWithAuctioneer = configAdmin.getConfiguration(%22net.powermatcher.core.auctioneer%22);%0A    %09//Configuration%5B%5D configurations = configAdmin.listConfigurations(%22(service.pid=net.powermatcher.core.auctioneer.Auctioneer)%22);%0A%0A    %09components = scrService.getComponents(%22net.powermatcher.core.auctioneer.Auctioneer%22);%0A    %09// Verify that there is exactly one Auctioneer configuration present%0A    %09assertNotNull(configWithAuctioneer);%0A    %09%0A    %09// bij toevoegen hiervan, een wiring exception%0A//    %09Auctioneer auctioneer = new Auctioneer();%0A//        auctioneer.activate(new PropertieBuilder().agentId(%22auctioneer%22)%0A//                                                  .clusterId(%22DefaultCluster%22)%0A//                                                  .priceUpdateRate(30)%0A//                                                  .marketBasis(TestClusterHelper.DEFAULT_MB)%0A//                                                  .build());%0A//        %0A
 %0A   

test auctioneer