I am looking for a class to access the files from the running container using the arquillian cube.
eg: docker_ubuntu running
has files \usr\share\config.json
I want to update the config.json file using the arquillian cube.
Note : I am aware of working thru docker exec commands.
I found the solution
dockerClient = DockerClientBuilder.getInstance().build();
dockerClient.copyArchiveToContainerCmd(getContainerIdUsingName("ui")).withRemotePath("/usr/share/nginx/html/config").withHostResource(hostConfigPath.getAbsolutePath()).withNoOverwriteDirNonDir(false).exec();
System.out.println("Copying");
Method to get the container Id - Required docker-java
public String getContainerIdUsingName(String containerName)
{
InspectContainerResponse containerInfo = dockerClient.inspectContainerCmd(containerName).exec();
return containerInfo.getId();
}
Related
I have started using the Xamarin plugin for Visual Studio to create an Android app.
I have a local SQL database, and I want to call it to display data. I don't see how I can do this. Is it possible?
After thinking this was a trivial thing to do, I was proven wrong when I tried setup a quick test project. This post will contain a full tutorial on setting up a DB for an Android App in Xamarin that will come in handy as a reference for future Xamarin users.
At a glance:
Add Sqlite.cs to your project.
Add your database file as an Asset.
Set your database file to build as an AndroidAsset.
Manually copy the database file out of your apk to another directory.
Open a database connetion using Sqlite.SqliteConnection.
Operate on the database using Sqlite.
Setting up a local database for a Xamarin Android project
1. Add Sqlite.cs to your project.
Start by going to this repository and downloading Sqlite.cs; this provides the Sqlite API that you can use to run queries against your db. Add the file to your project as a source file.
2. Add DB as asset.
Next, get your DB and copy it into the Assets directory of your Android project and then import it into your project so that it appears beneath the Assets folder within your solution:
I'm using the Chinook_Sqlite.sqlite database sample renamed to db.sqlite from this site throughout this example.
3. Set DB to build as AndroidAsset.
Right click on the DB file and set it to build action AndroidAsset. This will ensure that it is included into the assets directory of the APK.
4. Manually copy DB out of your APK.
As the DB is included as an Asset (packaged within the APK) you will need to extract it out.
You can do this with the following code:
string dbName = "db.sqlite";
string dbPath = Path.Combine (Android.OS.Environment.ExternalStorageDirectory.ToString (), dbName);
// Check if your DB has already been extracted.
if (!File.Exists(dbPath))
{
using (BinaryReader br = new BinaryReader(Android.App.Application.Context.Assets.Open(dbName)))
{
using (BinaryWriter bw = new BinaryWriter(new FileStream(dbPath, FileMode.Create)))
{
byte[] buffer = new byte[2048];
int len = 0;
while ((len = br.Read(buffer, 0, buffer.Length)) > 0)
{
bw.Write (buffer, 0, len);
}
}
}
}
This extracts the DB as a binary file from the APK and places it into the system external storage path. Realistically the DB can go wherever you want, I've just chosen to stick it here.
I also read that Android has a databases folder that will store databases directly; I couldn't get it to work so I've just ran with this method of using an existing DB.
5. Open DB Connection.
Now open a connection to the DB through the Sqlite.SqliteConnection class:
using (var conn = new SQLite.SQLiteConnection(dbPath))
{
// Do stuff here...
}
6. Operate on DB.
Lastly, as Sqlite.net is an ORM, you can operate on the database using your own data types:
public class Album
{
[PrimaryKey, AutoIncrement]
public int AlbumId { get; set; }
public string Title { get; set; }
public int ArtistId { get; set; }
}
// Other code...
using (var conn = new SQLite.SQLiteConnection(dbPath))
{
var cmd = new SQLite.SQLiteCommand (conn);
cmd.CommandText = "select * from Album";
var r = cmd.ExecuteQuery<Album> ();
Console.Write (r);
}
Summary
And that's how to add an existing Sqlite database to your Xamarin solution for Android! For more information check out the examples included with the Sqlite.net library, its unit tests and the examples in the Xamarin documentation.
Here is the one that I'm using and it's working
install the Sqlite plugin
create interface to access different platforms services
create a model for the table
implement the interface that you created earlier on all of the
platform you want to use
use the plugin to create, get, insert, etc on your table
for more detailed information check this
I am trying to use allure report with jbehave on Java using maven. So there is a package that has a java class that we can use to create the allure report.
I only imported that class and I added the class as a reportBuilder for the configuration of Jbehave, just like the code below.
...
import io.qameta.allure.jbehave.AllureJbehave
...
public class RunStories extends JUnitStories {
private AllureJbehave allureJBehave;
...
...
#Override
public Configuration configuration() {
// set path of results
System.setProperty("allure.results.directory", "build/allure-results")
// create AllureJbehave instance
allureJBehave = new AllureJbehave();
StoryReporterBuilder reporterBuilder = new StoryReporterBuilder()
.withReporters(allureJBehave)
.withCodeLocation(codeLocationFromClass(this.getClass()));
// create and return configuration instance
Configuration jBehaveConfiguration = new MostUsefulConfiguration();
jBehaveConfiguration
.useStoryReporterBuilder(reporterBuilder);
return jBehaveConfiguration;
}
}
But I am not getting the information for trends graphs, how can I add those values or add more information to the allure report ?
You might want to check the plugin file (allure.yml) you are using for Allure. in case there is none, you can add your own with the list of plugins you are interested to use and add it to your configuration.
You can also check the read access of your files. If you are using Jenkins (for example), sometimes there is some access rights that are inherited and that can cause some issues when read.
I have a JBehave project in which need to integrate with TestNG and Selenium grid which using this, this and this code in github (sorry since i cant past the entire code so only showing the reference) i have done the JBehave + TestNG + Selenium Grid.
But my problem is when using single Story file to execute in different Selenium node the jbehave report index.html file is shown for any one node only. I want to have separate report for each node in a single or more jbehave report index.html file. I should not run with two story files and all, how can i show separate report for each and every Selenium node in a single jbehave report html file.
I know the jbehave use freemarker for their report generation but i have no clue on how to override this and show report for each selenium nodes. Any idea please share.
Thanks in Advance.
I dont think combining Jbehave and TestNG is a better idea. Jbehave supports the stories and using testng, there would be of no use, like grouping, parameter,etc. There are existing JunitStories class which works fine with Jbehave. If your using it for organizing your test results, you can use customized Allure reporting tool for jbehave (link). You could use Jbehave + Allure + Selenium Grid architecture.
Finally tried a way and found it to be an temporary solution for it now.
Create a String variable that gets the details in Story Runner Class.
RemoteWebDriver driver = (RemoteWebDriver) DriverManager.getDriver();
String hostname = hng.getHostName(driver.getSessionId());
String browserName = driver.getCapabilities().getBrowserName();
String browserVersion = driver.getCapabilities().getVersion();
Then pass that value to the Story Embedded class as shown below.
Embedder storyEmbedder = new StoryEmbedder(driver, browserName + "v" + browserVersion);
In the Story Embedded class assign that String value as shown below
private WebDriver driver;
private static String name;
public StoryEmbedder(WebDriver driver, String hostname) {
this.driver = driver;
this.name = hostname;
}
Then in the Configuration method inside the useStoryReporterBuilder function add the following code.
.withRelativeDirectory(name) //where 'name' is the String variable refer above step.
like the return will be as follows
return new MostUsefulConfiguration()
.useStoryControls(new StoryControls().doDryRun(false).doSkipScenariosAfterFailure(false))
.useStoryLoader(
new LoadFromClasspath(embedderClass))
.useStoryParser(
new RegexStoryParser(
examplesTableFactory))
.useStoryPathResolver(new UnderscoredCamelCaseResolver())
.useStoryReporterBuilder(
new StoryReporterBuilder().withCodeLocation(CodeLocations.codeLocationFromClass(embedderClass))
.withDefaultFormats().withPathResolver(new ResolveToPackagedName())
.withViewResources(viewResources).withReporters(new MyStoryReporter())
.withFormats(Format.CONSOLE, Format.TXT, Format.HTML, Format.XML).withFailureTrace(true)
.withFailureTraceCompression(true).withCrossReference(xref).withRelativeDirectory(name)).useParameterConverters(parameterConverters)
// use '%' instead of '$' to identify parameters
.useStepPatternParser(new RegexPrefixCapturingPatternParser("%"));
Now i can have two folders based on browser and browser version.
If you guys have any better answer please do help by posting it.
Thanks in Advance.
In EF 6.1 you can run the command:
update-database -script
This generates the full SQL script for one or many migrations. The problem we found is that it does not generate the required "GO" statements for sql server. This is causing the SQL script to fail when it would otherwise succeed if run directly without the "-script" parameter.
Has anyone else run into this?
You can override the script generation behavior by creating a wrapper class around the SqlServerMigrationSqlGenerator class. This class contains an overloaded Generate() method which takes in arguments that represent the type of script block it's generating. You can override these methods to add "GO" statements before starting new script blocks.
public class ProdMigrationScriptBuilder : SqlServerMigrationSqlGenerator
{
protected override void Generate(HistoryOperation insertHistoryOperation)
{
Statement("GO");
base.Generate(insertHistoryOperation);
Statement("GO");
}
protected override void Generate(CreateProcedureOperation createProcedureOperation)
{
Statement("GO");
base.Generate(createProcedureOperation);
}
protected override void Generate(AlterProcedureOperation alterProcedureOperation)
{
Statement("GO");
base.Generate(alterProcedureOperation);
}
protected override void Generate(SqlOperation sqlOperation)
{
Statement("GO");
base.Generate(sqlOperation);
}
}
You will also need to set this class as the Sql Generator in your Configuration class constructor.
public Configuration()
{
AutomaticMigrationsEnabled = false;
// Add back this line when creating script files for production migration...
SetSqlGenerator("System.Data.SqlClient", new ProdMigrationScriptBuilder());
}
One gotcha to this approach is that while it works great for creating re-usable script files for SQL Server Enterprise Manager, the GO statements do not work when executing migrations locally. You can comment out the SetSqlGenerator line when working locally, then simply add it back when you are ready to create your deployment scripts.
If you are trying to alter a view using Sql('Alter View dbo.Foos As etc'), then you can avoid the
should be the first statement in a batch file error
without adding GO statements by putting the sql inside an EXEC command:
Sql(EXEC('Alter View dbo.Foos As etc'))
Reference:
https://stackoverflow.com/a/20352867/150342
I want to develop a multi-agent system and I want to run different agents from different containers. I'm using eclipse with Jade framework for this and i have no idea how to configure the "run configuration" for the project in order to accomplish this. So far I have this: -gui -container main:Sender;a1:Receiver;a2:Pong and I want to put agents a1 and a2 in a separate container. Please help.
When starting a new jade project I usually create a Coordinator agent with the methods to launch and destroy other agents. I think this is good practice as you can extend these methods to other agents if need be.
I hope that this will help.
First Run the Agent jade graphical user interface (Ejade) (By Installing the Ejade Library)
or you can run it on the console:
C:\java jade.Boot -gui (You have to fix the system variable path to "C:\..\jade.far" and create a variable name classpath = "C:\..\jdk7\")
Run the code that allows you to create a new container to deploy on it your agents.
import jade.core.ProfileImpl;
import jade.core.Runtime;
import jade.domain.ams;
import jade.wrapper.AgentContainer;
import jade.wrapper.AgentController;
public class ContainerDeploy {
public static void main(String[] args) {
try{
Runtime runtime=Runtime.instance();
ProfileImpl profileImpl = new ProfileImpl(false);
profileImpl.setParameter(ProfileImpl.MAIN_HOST, "localhost");
AgentContainer agentContainer=runtime.createAgentContainer(profileImpl);
AgentController agentcontroller1 = agentContainer.createNewAgent("Name of Agent", "com.package.AgentClass", new Object[]{});
agentController1.start();
}catch(Exception e) {
System.out.println("Runtime Error\t");
e.printStackTrace();
}
}
}