// Copyright 2006, 2007 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.tapestry.ioc;
import java.util.Arrays;
import java.util.List;
import java.util.jar.Manifest;
import org.apache.tapestry.ioc.test.IOCTestCase;
import org.testng.annotations.Test;
public class RegistryBuilderTest extends IOCTestCase
{
@Test
public void sub_module()
{
RegistryBuilder builder = new RegistryBuilder();
builder.add(MasterModule.class);
Registry r = builder.build();
// Borrowed from IntegrationTest, this will only work if both FredModule and BarneyModule
// are loaded.
NameListHolder service = r.getService("UnorderedNames", NameListHolder.class);
List<String> names = service.getNames();
assertEquals(names, Arrays.asList("Beta", "Gamma", "UnorderedNames"));
}
@Test
public void manifest()
{
RegistryBuilder builder = new RegistryBuilder();
String value = String.format("%s, %s, %s", FredModule.class.getName(), BarneyModule.class
.getName(), RegistryBuilderTestModule.class.getName());
Manifest mf = new Manifest();
mf.getMainAttributes().putValue(IOCConstants.MODULE_BUILDER_MANIFEST_ENTRY_NAME, value);
// A package private method. Add in the two modules as if they were listed in the manifest.
IOCUtilities.addModulesInManifest(builder, mf);
Registry registry = builder.build();
Square service = registry.getService(Square.class);
assertEquals(service.square(4), 16l);
// This proves that the IOC works, the service builder method was invoked, that the
// ClassFactory service was accessed and used.
assertEquals(service.toString(), "<Proxy for Square(org.apache.tapestry.ioc.Square)>");
}
}
|