// Copyright 2004, 2005 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.hivemind.impl;
import java.util.Collections;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.internal.ConfigurationPoint;
import org.apache.hivemind.internal.RegistryInfrastructure;
import org.apache.hivemind.internal.ServicePoint;
import org.apache.hivemind.internal.Visibility;
import org.apache.hivemind.test.HiveMindTestCase;
import org.easymock.MockControl;
/**
* Additional tests for {@link org.apache.hivemind.impl.RegistryInfrastructureImpl}. Much of the
* existing testing is, alas, integration (not unit) testing. Gradually hope to move more of that
* into this class.
*
* @author Howard Lewis Ship
* @since 1.1
*/
public class TestRegistryInfrastructure extends HiveMindTestCase
{
public void testGetMissingExtensionPoint()
{
RegistryInfrastructure r = new RegistryInfrastructureImpl(null, null);
try
{
r.getServicePoint("foo", null);
unreachable();
}
catch (ApplicationRuntimeException ex)
{
assertEquals(ImplMessages.noSuchServicePoint("foo"), ex.getMessage());
}
}
public void testGetUnqualifiedServicePoint()
{
RegistryInfrastructureImpl r = new RegistryInfrastructureImpl(null, null);
final ModuleImpl module1 = new ModuleImpl();
module1.setModuleId( "module1" );
final ServicePointImpl servicePoint1 = new ServicePointImpl();
servicePoint1.setModule( module1 );
servicePoint1.setExtensionPointId( "module1.foo" );
servicePoint1.setVisibility( Visibility.PUBLIC );
r.addServicePoint( servicePoint1 );
try
{
r.getServicePoint("foo", null);
unreachable();
}
catch (ApplicationRuntimeException ex)
{
assertEquals(ImplMessages.unqualifiedServicePoint( "foo", "\"module1.foo\""), ex.getMessage());
}
final ModuleImpl module2 = new ModuleImpl();
module2.setModuleId( "module2" );
final ServicePointImpl servicePoint2 = new ServicePointImpl();
servicePoint2.setModule( module2 );
servicePoint2.setExtensionPointId( "module2.foo" );
servicePoint2.setVisibility( Visibility.PUBLIC );
r.addServicePoint( servicePoint2 );
try
{
r.getServicePoint("foo", null);
unreachable();
}
catch (ApplicationRuntimeException ex)
{
assertEquals(ImplMessages.unqualifiedServicePoint( "foo", "\"module1.foo\", \"module2.foo\""), ex.getMessage());
}
}
/**
* Ensure that the Registry "locks down" after being started up.
*
* @since 1.1
*/
public void testDoubleStartup()
{
MockControl spc = newControl(ServicePoint.class);
ServicePoint sp = (ServicePoint) spc.getMock();
Runnable service = (Runnable) newMock(Runnable.class);
// Training
sp.getExtensionPointId();
spc.setReturnValue("hivemind.Startup");
sp.getServiceInterfaceClassName();
spc.setReturnValue(Runnable.class.getName());
sp.visibleToModule(null);
spc.setReturnValue(true);
sp.getService(Runnable.class);
spc.setReturnValue(service);
service.run();
replayControls();
RegistryInfrastructureImpl r = new RegistryInfrastructureImpl(null, null);
r.addServicePoint(sp);
r.startup();
verifyControls();
try
{
r.startup();
unreachable();
}
catch (IllegalStateException ex)
{
assertEquals(ImplMessages.registryAlreadyStarted(), ex.getMessage());
}
}
public void testUnknownServiceModelFactory()
{
MockControl cpc = newControl(ConfigurationPoint.class);
ConfigurationPoint cp = (ConfigurationPoint) cpc.getMock();
// Training
cp.getExtensionPointId();
cpc.setReturnValue("hivemind.ServiceModels");
cp.visibleToModule(null);
cpc.setReturnValue(true);
cp.getElements();
cpc.setReturnValue(Collections.EMPTY_LIST);
replayControls();
RegistryInfrastructureImpl r = new RegistryInfrastructureImpl(null, null);
r.addConfigurationPoint(cp);
try
{
r.getServiceModelFactory("unknown");
unreachable();
}
catch (ApplicationRuntimeException ex)
{
assertEquals(ImplMessages.unknownServiceModel("unknown"), ex.getMessage());
}
verifyControls();
}
}