How to handle Multiple Base Path in RestAssured API Testing Framework? - rest-assured

In my case, I have multiple Base basePath.
Eg: Base URI- > http://reg10xx.cwx.local/API/Admin
BasePath1->/User
EndPoint->/List
The problem arises here.
Base URI-> http://reg10xx.cwx.local/API/Admin
BasePath2->/Organisation
EndPoint->/Roles.
Here is my case problem is with BasePath 1 and Base Path 2.
As in TestBase.java Class in Before Suite I have used
RestAssured.baseURI = configProperties.getBaseURI();
RestAssured.basePath = configProperties.getBasePath();
now I want to set my 2nd base path then is there any solution to this?

One solution I can think of here is to set the base URL path at the test case/helper method level rather than setting it at the class level.
Example:
RequestSpecBuilder build;
build = new RequestSpecBuilder();
build.setBaseUri ("https://maps.googleapis.com");

I am not sure what is yourbaseurl it , but you can parameterize yhe baseurl .
Then in Basepath mention the path which is common for both Admin and roles .
After that pass the path which completes the URI example -roles
import io.restassured.RestAssured;
import io.restassured.response.Response;
RestAssured.baseURI = "http://reg10xx.cwx.local/";
RestAssured.basePath = "API;
Response admin= get("Admin");
Response roles= get("Roles");

Related

Dart how to explicitly say which package class to use?

I have a Dart (Flutter) application that is making use of both the location and map_view packages. My problem is that both of these define a "Location" class.
How can I explicitly state which of the two classes I am using in any particular invocation?
e.g. I tried prefixing the class name with the package name:
location.Location = new Location();
map_view.Location = new Location(45.5231233, -122.6733130);
But Dart doesn't seem to like this syntax.
Found the answer. You have to give the libraries a prefix as per: https://www.dartlang.org/guides/language/language-tour#libraries-and-visibility
after which you can use the prefix in the class name to make it work:
import 'package:location/location.dart' as locLib;
import 'package:map_view/map_view.dart' as mapViewLib;
locLib.Location = new Location();
mapViewLib.Location = new Location(45.5231233, -122.6733130);

How do I copy DOORS modules between folders/projects using DXL?

I am new to both DOORS and DXL. I've been trying to copy a module in a project template to any given project folder using DXL, but my approaches haven't been working. Here's the part of my script where the copy and paste operations are attempted:
// Where string originalModule is the path to the module being copied.
// Where string targetPath is the path to where the copied module should be pasted.
ModName_ originalMMP = module(originalModule)
string originalMMPdesc = description(originalMMP)
clipCopy(originalMMP)
clipPaste(targetPath)
clipClear()
Whenever I run my script in the DOORS' DXL editor, I get an error indicating that the functions clipCopy() and clipPaste() have invalid arguments. In the DXL reference manual, it indicates that the type of the arguments should be of Item type, but I'm not totally sure I'm understanding that.
I have tried this other approach as well:
// The same conventions as above are used for the originalModule and targetPath
// string type variables.
// The variable string targetPathTemp contains the path to the replicated
// file New Module Temp
ModName_ originalMMP = module(originalModule)
string originalMMPdesc = description(originalMMP)
bool OK = copy(originalMMP,"New Module Temp", originalMMPdesc)
ModName_ newMMP = module(targetPathTemp)
// Moving and Renaming:
ErrMess = move(newMMP, targetPath)
ErrMess = rename(copiedMMP,newModuleName, originalMMPdesc)
I get the same errors as clipCopy() and clipPaste() for the functions: copy() and move().
Does anyone have any idea of what am I doing wrong, and what exactly am I not understanding?
Thanks in advance!
I think clipCopy and its brethren only work with Items. Use Item originalMMP = item(originalModule) instead of ModName_...

How to pass configuration to a module

What's the right way to pass some configuration parameters to a module that I wrote for neo4j + GraphAware? I believe there should be a way that I can put some config entries in neo4j.conf and read them in my module's code but so far I could not find it.
There is definitely a possibility to pass configuration parameters to your module.
The best way is to look at other modules that use such configuration, GraphAware not being shy to open source modules (https://github.com/graphaware?utf8=%E2%9C%93&q=&type=&language=java) you can find plenty of it.
Let's take the uuid-module as an example :
In the bootstrapper class, you will find the logic for reading configuration parameters from the config file :
String uuidProperty = config.get(UUID_PROPERTY);
if (StringUtils.isNotBlank(uuidProperty)) {
configuration = configuration.withUuidProperty(uuidProperty);
LOG.info("uuidProperty set to %s", configuration.getUuidProperty());
}
https://github.com/graphaware/neo4j-uuid/blob/master/src/main/java/com/graphaware/module/uuid/UuidBootstrapper.java#L55
The found parameters are used to create an immutable Configuration class :
https://github.com/graphaware/neo4j-uuid/blob/master/src/main/java/com/graphaware/module/uuid/UuidConfiguration.java
The end of the module bootstrapping will then pass the configuration object to the constructor of the module :
return new UuidModule(moduleId, configuration, database);
https://github.com/graphaware/neo4j-uuid/blob/master/src/main/java/com/graphaware/module/uuid/UuidBootstrapper.java#L89
You can then use this module with the configuration :
public UuidModule(String moduleId, UuidConfiguration configuration, GraphDatabaseService database) {
super(moduleId);
this.uuidConfiguration = configuration;
this.uuidGenerator = instantiateUuidGenerator(configuration, database);
this.uuidIndexer = new LegacyIndexer(database, configuration);
}
https://github.com/graphaware/neo4j-uuid/blob/master/src/main/java/com/graphaware/module/uuid/UuidModule.java

Maximum recursion getting shared service

I have defined two classes (Environment and ConfigurationReader). Both are registered as shared dependencies.
The Environment class tries get the current environment, but for this, needs read a configuration file via ConfigurationReader.
The sequence diagram is:
The classes are:
class Environment
{
...
public function resolve()
{
$config = DI::getDefault()->getCfg();
$config->getValue('pepe', 'db_name');
}
...
}
class ConfigurationReader
{
...
public function getValue($aConfig, $aKey)
{
$path = $this->getFile($aConfig);
}
protected function getFile($aConfig)
{
$env = DI::getDefault()->getEnv();
$path = 'config/' . $env->getShortName() . '/' . $aConfig . '.yml';
return $path;
}
...
}
And are registered and created in the index.php:
...
$di = new FactoryDefault();
$di->setShared('env', function() use ($di) {
$env = new Services\Environment($di);
$env->resolve();
return $env;
});
$di->setShared('cfg', function() use ($di) {
return new Services\ConfigurationReader($di);
});
$di->getShared('cfg');
$di->getShared('env');
...
So, PHP crash at $config = DI::getDefault()->getCfg(); and says:
PHP Fatal error: Maximum recursion depth exceeded
Any ideas ?
A couple remarks
You're passing the di to the constructor, but end up getting it statically (DI::getDefault())
regarding the infinite loop, it's because cfg needs env who needs cfg who needs env etc.....
To have the framework automatically injecting the DI into your service you should either implement InjectionAwareInterface (https://docs.phalconphp.com/en/latest/reference/di.html#automatic-injecting-of-the-di-itself) or
extend the Component class (If you need event management too, use Plugin instead of Component ). Have a look at this discussion : https://forum.phalconphp.com/discussion/383/plugin-vs-component-what-s-the-difference-
Regarding your use case, you don't give enough context for an exhaustive answer, but I think you could simplify it as:
ConfigService: Unless you use configs from different env namespaces, you should pass the value of $env->getShortName() value to the service constructor (without getting it from the env service). In our apps the env is determined by nginx based on the domain name or other parameters and passed as an environment variable to php. Also, if you don't have hundreds of config files, and your app heavily relies on them, you should read and parse them once on instantiation and store the configs in the service (as associative array, config objects, or whatever you prefer). Add some cache layer to avoid wasting resource parsing all your files on each request. Phalcons provide The Config component to do so. It comes with file adapters (only ini and associative array format but you could easily implement your own yml adapter). If most of your app config relies on configurable values, that will probably be the first component you want to instantiate (or at least declare in the di). It shouldn't dependencies to other services.
EnvService: You can access your config values by calling the config service (If you have it to extend Component, you can do something like $this->cfg->getValue($key)).

How to read file from an imported library

I have two packages: webserver and utils which provides assets to webserver.
The webserver needs access to static files inside utils. So I have this setup:
utils/
lib/
static.html
How can I access the static.html file in one of my dart scripts in webserver?
EDIT: What I tried so far, is to use mirrors to get the path of the library, and read it from there. The problem with that approach is, that if utils is included with package:, the url returned by currentMirrorSystem().findLibrary(#utils).uri is a package uri, that can't be transformed to an actual file entity.
Use the Resource class, a new class in Dart SDK 1.12.
Usage example:
var resource = new Resource('package:myapp/myfile.txt');
var contents = await resource.loadAsString();
print(contents);
This works on the VM, as of 1.12.
However, this doesn't directly address your need to get to the actual File entity, from a package: URI. Given the Resource class today, you'd have to route the bytes from loadAsString() into the HTTP server's Response object.
I tend to use Platform.script or mirrors to find the main package top folder (i.e. where pubspec.yaml is present) and find imported packages exported assets. I agree this is not a perfect solution but it works
import 'dart:io';
import 'package:path/path.dart';
String getProjectTopPath(String resolverPath) {
String dirPath = normalize(absolute(resolverPath));
while (true) {
// Find the project root path
if (new File(join(dirPath, "pubspec.yaml")).existsSync()) {
return dirPath;
}
String newDirPath = dirname(dirPath);
if (newDirPath == dirPath) {
throw new Exception("No project found for path '$resolverPath");
}
dirPath = newDirPath;
}
}
String getPackagesPath(String resolverPath) {
return join(getProjectTopPath(resolverPath), 'packages');
}
class _TestUtils {}
main(List<String> arguments) {
// User Platform.script - does not work in unit test
String currentScriptPath = Platform.script.toFilePath();
String packagesPath = getPackagesPath(currentScriptPath);
// Get your file using the package name and its relative path from the lib folder
String filePath = join(packagesPath, "utils", "static.html");
print(filePath);
// use mirror to find this file path
String thisFilePath = (reflectClass(_TestUtils).owner as LibraryMirror).uri.toString();
packagesPath = getPackagesPath(thisFilePath);
filePath = join(packagesPath, "utils", "static.html");
print(filePath);
}
To note that since recently Platform.script is not reliable in unit test when using the new test package so you might use the mirror tricks that I propose above and explained here: https://github.com/dart-lang/test/issues/110

Resources