/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package org.arquillian.liferay.test;

import com.liferay.portal.model.Release;
import com.liferay.portal.service.ReleaseLocalService;

import java.io.InputStream;

import java.util.UUID;

import org.arquillian.container.liferay.remote.enricher.Inject;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.osgi.metadata.OSGiManifestBuilder;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.Asset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;

/**
 * @author Cristina González
 */
@RunWith(Arquillian.class)
public class TestInjections {

	@Deployment
	public static JavaArchive create() {
		final JavaArchive archive = ShrinkWrap.create(
			JavaArchive.class, "bundle" + UUID.randomUUID() + ".jar");

		archive.setManifest(new Asset() {
			@Override
			public InputStream openStream() {
				OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
				builder.addBundleSymbolicName("bundle");
				builder.addBundleManifestVersion(2);
				builder.addImportPackages(
					ReleaseLocalService.class.getPackage().getName());
				builder.addImportPackages(Release.class.getPackage().getName());
				return builder.openStream();
			}
		});
		return archive;
	}

	@Test
	public void shouldInjectBundle() {
		Assert.assertNotNull(_bundle);
		Assert.assertEquals("bundle", _bundle.getSymbolicName());
	}

	@Test
	public void shouldInjectBundleCOntext() {
		Assert.assertNotNull(_bundleContext);
		Assert.assertEquals(_bundle, _bundleContext.getBundle());
	}

	@Test
	public void shouldInjectReleaseLocalService() {
		Assert.assertNotNull(_releaseLocalService);

		Release releasePortal = _releaseLocalService.fetchRelease("portal");

		Assert.assertEquals(7000, releasePortal.getBuildNumber());
	}

	@ArquillianResource
	private Bundle _bundle;

	@ArquillianResource
	private BundleContext _bundleContext;

	@Inject
	private ReleaseLocalService _releaseLocalService;

}
@@ -740,43 +740,12 @@
 .io.
-InputStream;%0A%0Aimport java.util.UUID
+File
 ;%0A%0Ai
@@ -974,60 +974,8 @@
 ce;%0A
-import org.jboss.osgi.metadata.OSGiManifestBuilder;%0A
 impo
@@ -1050,19 +1050,24 @@
 api.
-asset.Asset
+spec.JavaArchive
 ;%0Aim
@@ -1092,36 +1092,42 @@
 inkwrap.
-api.spec.JavaArchive
+osgi.api.BndProjectBuilder
 ;%0A%0Aimpor
@@ -1146,16 +1146,41 @@
 Assert;%0A
+import org.junit.Ignore;%0A
 import o
@@ -1456,517 +1456,213 @@
 %7B%0A%09%09
-final JavaArchive archive = ShrinkWrap.create(%0A%09%09%09JavaArchive.class, %22bundle%22 + UUID.randomUUID() + %22.jar%22);%0A%0A%09%09archive.setManifest(new Asset() %7B%0A%09%09%09@Override%0A%09%09%09public InputStream openStream() %7B%0A%09%09%09%09OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();%0A%09%09%09%09builder.addBundleSymbolicNam
+BndProjectBuilder bndProjectBuilder = ShrinkWrap.create(%0A%09%09%09BndProjectBuilder.class);%0A%0A%09%09bndProjectBuilder.setBndFile(new Fil
 e(%22b
-u
 nd
-le%22);%0A%09%09%09%09builder.addBundleManifestVersion(2);%0A%09%09%09%09builder.addImportPackages(%0A%09%09%09%09%09ReleaseLocalService.class.getPackage().getName(
+-basic-portlet-test.bnd%22
 ));%0A
-%09%09%09%09builder.addImportPackages(Release.class.getPackage().getName());%0A%09%09
+%0A%09%09bndProjectBuilder.generateManifest(true);%0A%0A
 %09%09re
@@ -1671,56 +1671,46 @@
 rn b
-uilder.openStream();%0A%09%09%09%7D%0A%09%09%7D);%0A%09%09return archive
+ndProjectBuilder.as(JavaArchive.class)
 ;%0A%09%7D
@@ -1813,13 +1813,40 @@
 als(
-%22bund
+%0A%09%09%09%22org.arquillian.liferay.samp
 le%22,

Use BND for the deployment of the test