Skip to content

Commit

Permalink
feat: add some npm tests (#61)
Browse files Browse the repository at this point in the history
closes #37
  • Loading branch information
fdelbrayelle authored May 28, 2020
1 parent 88236a1 commit 8ba3be4
Show file tree
Hide file tree
Showing 9 changed files with 434 additions and 41 deletions.
2 changes: 0 additions & 2 deletions generators/app/templates/dummy.txt

This file was deleted.

2 changes: 0 additions & 2 deletions generators/entity/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ module.exports = class extends BaseGenerator {
this.template = function(source, destination) {
this.fs.copyTpl(this.templatePath(source), this.destinationPath(destination), this);
};

this.template('dummy.txt', 'dummy.txt', this, {});
},

updateConfig() {
Expand Down
2 changes: 0 additions & 2 deletions generators/entity/templates/dummy.txt

This file was deleted.

77 changes: 54 additions & 23 deletions test/app.spec.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,58 @@
/* eslint-disable no-unused-expressions */
// const path = require('path');
// const fse = require('fs-extra');
// const helpers = require('yeoman-test');
// const expect = require('chai').expect;
const assert = require('yeoman-assert');
const constants = require('generator-jhipster/generators/generator-constants');
const expect = require('chai').expect;
const fse = require('fs-extra');
const helpers = require('yeoman-test');
const path = require('path');

describe('JHipster generator kafka', () => {
// describe('Test with no message broker', () => {
// it('throws an error', done => {
// helpers
// .run(path.join(__dirname, '../generators/app'))
// .inTmpDir(dir => {
// fse.copySync(path.join(__dirname, '../test/templates/no-message-broker'), dir);
// })
// .withOptions({
// testmode: true
// })
// .withPrompts({
// message: 'simple message to say hello'
// })
// .on('error', error => {
// expect(error.message.includes('You need to have Kafka as message broker')).to.be.true;
// done();
// });
// });
// });
describe('with no message broker', () => {
it('throws an error', done => {
helpers
.run(path.join(__dirname, '../generators/app'))
.inTmpDir(dir => {
fse.copySync(path.join(__dirname, '../test/templates/no-message-broker'), dir);
})
.on('error', error => {
expect(error.message === 'You need to use Kafka as message broker!').to.be.true;
})
.on('end', () => {
expect(true).to.be.false;
});
done();
});
});

describe('with a consumer and a producer for a single entity', () => {
before(done => {
helpers
.run(path.join(__dirname, '../generators/app'))
.inTmpDir(dir => {
fse.copySync(path.join(__dirname, '../test/templates/message-broker-with-entities'), dir);
})
.withPrompts({
components: ['consumer', 'producer'],
entities: ['Foo']
})
.on('end', done);
});

it('generates default files', () => {
const expectedFiles = [
`${constants.SERVER_MAIN_SRC_DIR}com/mycompany/myapp/config/KafkaProperties.java`,
`${constants.SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/kafka/GenericConsumer.java`,
`${constants.SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/kafka/consumer/FooConsumer.java`,
`${constants.SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/kafka/deserializer/FooDeserializer.java`,
`${constants.SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/kafka/producer/FooProducer.java`,
`${constants.SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/kafka/serializer/FooSerializer.java`
];
assert.file(expectedFiles);
});

it('updates application.yml files', () => {
assert.fileContent(`${constants.SERVER_MAIN_RES_DIR}config/application.yml`, /foo:/);
assert.fileContent(`${constants.SERVER_TEST_RES_DIR}config/application.yml`, /foo:/);
});
});
});
20 changes: 20 additions & 0 deletions test/templates/message-broker-with-entities/.jhipster/Foo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"fluentMethods": true,
"clientRootFolder": "",
"relationships": [],
"fields": [
{
"fieldName": "bar",
"fieldType": "String"
}
],
"changelogDate": "20200528075136",
"dto": "no",
"searchEngine": false,
"service": "no",
"entityTableName": "foo",
"databaseType": "sql",
"readOnly": false,
"jpaMetamodelFiltering": false,
"pagination": "no"
}
40 changes: 40 additions & 0 deletions test/templates/message-broker-with-entities/.yo-rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"generator-jhipster": {
"promptValues": {
"packageName": "com.mycompany.myapp"
},
"jhipsterVersion": "6.9.0",
"applicationType": "monolith",
"baseName": "message_broker_with_entities",
"packageName": "com.mycompany.myapp",
"packageFolder": "com/mycompany/myapp",
"serverPort": "8080",
"authenticationType": "jwt",
"cacheProvider": "ehcache",
"enableHibernateCache": true,
"websocket": false,
"databaseType": "sql",
"devDatabaseType": "h2Disk",
"prodDatabaseType": "mysql",
"searchEngine": false,
"messageBroker": "kafka",
"serviceDiscoveryType": false,
"buildTool": "maven",
"enableSwaggerCodegen": false,
"jwtSecretKey": "NzVhNjIzZWRjNDY5ZjY5NmYwZjIyNjQwNzAzZTIxYmZjOGRlNzU2MjIxYmYyZTQ2NzdjNTI2MGZhN2U0YWRlM2E3MWJjMzBmYjlhYzljOTQ5NWU2YTIzMWRiMWIxNDU3ZTQ0YjU5ZWNkMDE2Yjg5NjRiYTViNDBmNmRjMjVkMjk=",
"embeddableLaunchScript": false,
"useSass": true,
"clientPackageManager": "npm",
"clientFramework": "angularX",
"clientTheme": "none",
"clientThemeVariant": "",
"creationTimestamp": 1590651818341,
"testFrameworks": [],
"jhiPrefix": "jhi",
"entitySuffix": "",
"dtoSuffix": "DTO",
"otherModules": [],
"enableTranslation": false,
"blueprints": []
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# ===================================================================
# Spring Boot configuration.
#
# This configuration will be overridden by the Spring profile you use,
# for example application-dev.yml if you use the "dev" profile.
#
# More information on profiles: https://www.jhipster.tech/profiles/
# More information on configuration properties: https://www.jhipster.tech/common-application-properties/
# ===================================================================

# ===================================================================
# Standard Spring Boot properties.
# Full reference is available at:
# http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
# ===================================================================

management:
endpoints:
web:
base-path: /management
exposure:
include: ['configprops', 'env', 'health', 'info', 'jhimetrics', 'logfile', 'loggers', 'prometheus', 'threaddump']
endpoint:
health:
show-details: when_authorized
roles: 'ROLE_ADMIN'
jhimetrics:
enabled: true
info:
git:
mode: full
health:
mail:
enabled: false # When using the MailService, configure an SMTP server and set this to true
metrics:
export:
# Prometheus is the default metrics backend
prometheus:
enabled: true
step: 60
enable:
http: true
jvm: true
logback: true
process: true
system: true
distribution:
percentiles-histogram:
all: true
percentiles:
all: 0, 0.5, 0.75, 0.95, 0.99, 1.0
tags:
application: ${spring.application.name}
web:
server:
request:
autotime:
enabled: true

spring:
autoconfigure:
exclude: org.springframework.boot.actuate.autoconfigure.metrics.jdbc.DataSourcePoolMetricsAutoConfiguration
application:
name: message_broker_with_entities
profiles:
# The commented value for `active` can be replaced with valid Spring profiles to load.
# Otherwise, it will be filled in by maven when building the JAR file
# Either way, it can be overridden by `--spring.profiles.active` value passed in the commandline or `-Dspring.profiles.active` set in `JAVA_OPTS`
active: #spring.profiles.active#
jmx:
enabled: false
data:
jpa:
repositories:
bootstrap-mode: deferred
jpa:
open-in-view: false
properties:
hibernate.jdbc.time_zone: UTC
hibernate.id.new_generator_mappings: true
hibernate.connection.provider_disables_autocommit: true
hibernate.cache.use_second_level_cache: true
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: false
# modify batch size as necessary
hibernate.jdbc.batch_size: 25
hibernate.order_inserts: true
hibernate.order_updates: true
hibernate.query.fail_on_pagination_over_collection_fetch: true
hibernate.query.in_clause_parameter_padding: true
hibernate:
ddl-auto: none
naming:
physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
messages:
basename: i18n/messages
main:
allow-bean-definition-overriding: true
task:
execution:
thread-name-prefix: message-broker-with-entities-task-
pool:
core-size: 2
max-size: 50
queue-capacity: 10000
scheduling:
thread-name-prefix: message-broker-with-entities-scheduling-
pool:
size: 2
thymeleaf:
mode: HTML
output:
ansi:
console-available: true

server:
servlet:
session:
cookie:
http-only: true

# Properties to be exposed on the /info management endpoint
info:
# Comma separated list of profiles that will trigger the ribbon to show
display-ribbon-on-profiles: 'dev'

# ===================================================================
# JHipster specific properties
#
# Full reference is available at: https://www.jhipster.tech/common-application-properties/
# ===================================================================

jhipster:
clientApp:
name: 'messageBrokerWithEntitiesApp'
# By default CORS is disabled. Uncomment to enable.
# cors:
# allowed-origins: "*"
# allowed-methods: "*"
# allowed-headers: "*"
# exposed-headers: "Authorization,Link,X-Total-Count"
# allow-credentials: true
# max-age: 1800
mail:
from: message_broker_with_entities@localhost
swagger:
default-include-pattern: /api/.*
title: message_broker_with_entities API
description: message_broker_with_entities API documentation
version: 0.0.1
terms-of-service-url:
contact-name:
contact-url:
contact-email:
license:
license-url:
kafka:
bootstrap-servers: localhost:9092
consumer:
key.deserializer: org.apache.kafka.common.serialization.StringDeserializer
value.deserializer: org.apache.kafka.common.serialization.StringDeserializer
group.id: message-broker-with-entities
auto.offset.reset: earliest
producer:
key.serializer: org.apache.kafka.common.serialization.StringSerializer
value.serializer: org.apache.kafka.common.serialization.StringSerializer
# ===================================================================
# Application specific properties
# Add your own application properties here, see the ApplicationProperties class
# to have type-safe configuration, like in the JHipsterProperties above
#
# More documentation is available at:
# https://www.jhipster.tech/common-application-properties/
# ===================================================================

# application:
Loading

0 comments on commit 8ba3be4

Please sign in to comment.